(t *testing.T)
| 2803 | } |
| 2804 | |
| 2805 | func Test_generateCompareURL(t *testing.T) { |
| 2806 | tests := []struct { |
| 2807 | name string |
| 2808 | ctx CreateContext |
| 2809 | state shared.IssueMetadataState |
| 2810 | httpStubs func(*testing.T, *httpmock.Registry) |
| 2811 | projectsV1Support gh.ProjectsV1Support |
| 2812 | want string |
| 2813 | wantErr bool |
| 2814 | }{ |
| 2815 | { |
| 2816 | name: "basic", |
| 2817 | ctx: CreateContext{ |
| 2818 | PRRefs: &skipPushRefs{ |
| 2819 | qualifiedHeadRef: shared.NewQualifiedHeadRefWithoutOwner("feature"), |
| 2820 | baseRepo: api.InitRepoHostname(&api.Repository{Name: "REPO", Owner: api.RepositoryOwner{Login: "OWNER"}}, "github.com"), |
| 2821 | baseBranchName: "main", |
| 2822 | }, |
| 2823 | }, |
| 2824 | want: "https://github.com/OWNER/REPO/compare/main...feature?body=&expand=1", |
| 2825 | wantErr: false, |
| 2826 | }, |
| 2827 | { |
| 2828 | name: "with labels", |
| 2829 | ctx: CreateContext{ |
| 2830 | PRRefs: &skipPushRefs{ |
| 2831 | qualifiedHeadRef: shared.NewQualifiedHeadRefWithoutOwner("b"), |
| 2832 | baseRepo: api.InitRepoHostname(&api.Repository{Name: "REPO", Owner: api.RepositoryOwner{Login: "OWNER"}}, "github.com"), |
| 2833 | baseBranchName: "a", |
| 2834 | }, |
| 2835 | }, |
| 2836 | state: shared.IssueMetadataState{ |
| 2837 | Labels: []string{"one", "two three"}, |
| 2838 | }, |
| 2839 | want: "https://github.com/OWNER/REPO/compare/a...b?body=&expand=1&labels=one%2Ctwo+three", |
| 2840 | wantErr: false, |
| 2841 | }, |
| 2842 | { |
| 2843 | name: "'/'s in branch names/labels are percent-encoded", |
| 2844 | ctx: CreateContext{ |
| 2845 | PRRefs: &skipPushRefs{ |
| 2846 | qualifiedHeadRef: mustParseQualifiedHeadRef("ORIGINOWNER:feature"), |
| 2847 | baseRepo: api.InitRepoHostname(&api.Repository{Name: "REPO", Owner: api.RepositoryOwner{Login: "UPSTREAMOWNER"}}, "github.com"), |
| 2848 | baseBranchName: "main/trunk", |
| 2849 | }, |
| 2850 | }, |
| 2851 | want: "https://github.com/UPSTREAMOWNER/REPO/compare/main%2Ftrunk...ORIGINOWNER:feature?body=&expand=1", |
| 2852 | wantErr: false, |
| 2853 | }, |
| 2854 | { |
| 2855 | name: "Any of !'(),; but none of $&+=@ and : in branch names/labels are percent-encoded ", |
| 2856 | /* |
| 2857 | - Technically, per section 3.3 of RFC 3986, none of !$&'()*+,;= (sub-delims) and :[]@ (part of gen-delims) in path segments are optionally percent-encoded, but url.PathEscape percent-encodes !'(),; anyway |
| 2858 | - !$&'()+,;=@ is a valid Git branch name—essentially RFC 3986 sub-delims without * and gen-delims without :/?#[] |
| 2859 | - : is GitHub separator between a fork name and a branch name |
| 2860 | - See https://github.com/golang/go/issues/27559. |
| 2861 | */ |
| 2862 | ctx: CreateContext{ |
nothing calls this directly
no test coverage detected