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