Skip to content

Commit 25ec62b

Browse files
fix(browse): Update browse URLs
GL 16 removed support for many URLs that used the "legacy" format without a namespace delimiter (ie w/o `/-/`). The delimiter is now required and the old URLs are returning 404s. Deprecation notice: https://docs.gitlab.com/ee/update/deprecations.html?removal_milestone=16.0#legacy-urls-replaced-or-removed List of affected URLs: https://gitlab.com/gitlab-org/gitlab/-/issues/28848#release-notes
1 parent 736a415 commit 25ec62b

11 files changed

+25
-25
lines changed

cmd/issue_browse.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ var issueBrowseCmd = &cobra.Command{
3131

3232
// path.Join will remove 1 "/" from "http://" as it's consider that's
3333
// file system path. So we better use normal string concat
34-
issueURL := project.WebURL + "/issues"
34+
issueURL := project.WebURL + "/-/issues"
3535
if num > 0 {
3636
issueURL = issueURL + "/" + strconv.FormatInt(num, 10)
3737
}

cmd/issue_browse_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ func Test_issueBrowse(t *testing.T) {
1111
defer func() { browse = oldBrowse }()
1212

1313
browse = func(url string) error {
14-
require.Equal(t, "https://gitlab.com/zaquestion/test/issues/1", url)
14+
require.Equal(t, "https://gitlab.com/zaquestion/test/-/issues/1", url)
1515
return nil
1616
}
1717

cmd/issue_note_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ func Test_issueCreateNote(t *testing.T) {
2020
t.Fatal(err)
2121
}
2222

23-
require.Contains(t, string(b), "https://gitlab.com/lab-testing/test/issues/1#note_")
23+
require.Contains(t, string(b), "https://gitlab.com/lab-testing/test/-/issues/1#note_")
2424
}
2525

2626
func Test_issueReplyNote(t *testing.T) {

cmd/mr_browse.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ var mrBrowseCmd = &cobra.Command{
2828
if err != nil {
2929
log.Fatal(err)
3030
}
31-
hostURL.Path = path.Join(hostURL.Path, rn, "merge_requests")
31+
hostURL.Path = path.Join(hostURL.Path, rn, "-", "merge_requests")
3232
hostURL.Path = path.Join(hostURL.Path, strconv.FormatInt(num, 10))
3333

3434
err = browse(hostURL.String())

cmd/mr_browse_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ func Test_mrBrowseWithParameter(t *testing.T) {
1212
defer func() { browse = oldBrowse }()
1313

1414
browse = func(url string) error {
15-
require.Equal(t, "https://gitlab.com/zaquestion/test/merge_requests/1", url)
15+
require.Equal(t, "https://gitlab.com/zaquestion/test/-/merge_requests/1", url)
1616
return nil
1717
}
1818

@@ -39,7 +39,7 @@ func Test_mrBrowseCurrent(t *testing.T) {
3939
defer func() { browse = oldBrowse }()
4040

4141
browse = func(url string) error {
42-
require.Equal(t, "https://gitlab.com/zaquestion/test/merge_requests/3", url)
42+
require.Equal(t, "https://gitlab.com/zaquestion/test/-/merge_requests/3", url)
4343
return nil
4444
}
4545

cmd/mr_discussion_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func Test_mrCreateDiscussion(t *testing.T) {
2424
t.Fatal(err)
2525
}
2626

27-
require.Contains(t, string(b), "https://gitlab.com/lab-testing/test/merge_requests/"+mrCommentSlashDiscussionDumpsterID+"#note_")
27+
require.Contains(t, string(b), "https://gitlab.com/lab-testing/test/-/merge_requests/"+mrCommentSlashDiscussionDumpsterID+"#note_")
2828
}
2929

3030
func Test_mrCreateDiscussion_file(t *testing.T) {
@@ -45,7 +45,7 @@ func Test_mrCreateDiscussion_file(t *testing.T) {
4545
t.Fatal(err)
4646
}
4747

48-
require.Contains(t, string(b), "https://gitlab.com/lab-testing/test/merge_requests/"+mrCommentSlashDiscussionDumpsterID+"#note_")
48+
require.Contains(t, string(b), "https://gitlab.com/lab-testing/test/-/merge_requests/"+mrCommentSlashDiscussionDumpsterID+"#note_")
4949
}
5050

5151
func Test_mrDiscussionMsg(t *testing.T) {

cmd/mr_note_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ func Test_mrCreateNote(t *testing.T) {
2323
{
2424
Name: "Normal text",
2525
Args: []string{"lab-testing", mrCommentSlashDiscussionDumpsterID, "-m", "note text"},
26-
ExpectedBody: "https://gitlab.com/lab-testing/test/merge_requests/" + mrCommentSlashDiscussionDumpsterID + "#note_",
26+
ExpectedBody: "https://gitlab.com/lab-testing/test/-/merge_requests/" + mrCommentSlashDiscussionDumpsterID + "#note_",
2727
},
2828
{
2929
// Escaped sequence text direct in the argument list as the
3030
// following one was already a problem:
3131
// https://github.com/zaquestion/lab/issues/376
3232
Name: "Escape char",
3333
Args: []string{"lab-testing", mrCommentSlashDiscussionDumpsterID, "-m", "{\"key\": \"value\"}"},
34-
ExpectedBody: "https://gitlab.com/lab-testing/test/merge_requests/" + mrCommentSlashDiscussionDumpsterID + "#note_",
34+
ExpectedBody: "https://gitlab.com/lab-testing/test/-/merge_requests/" + mrCommentSlashDiscussionDumpsterID + "#note_",
3535
},
3636
}
3737
noteCmd := []string{"mr", "note"}
@@ -71,7 +71,7 @@ func Test_mrCreateNote_file(t *testing.T) {
7171
t.Fatal(err)
7272
}
7373

74-
require.Contains(t, string(b), "https://gitlab.com/lab-testing/test/merge_requests/"+mrCommentSlashDiscussionDumpsterID+"#note_")
74+
require.Contains(t, string(b), "https://gitlab.com/lab-testing/test/-/merge_requests/"+mrCommentSlashDiscussionDumpsterID+"#note_")
7575
}
7676

7777
func Test_mrReplyAndResolve(t *testing.T) {

cmd/mr_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ func Test_mrCmd_MR_description_and_options(t *testing.T) {
200200

201201
t.Log("commentID =", commentID)
202202

203-
url := "https://gitlab.com/lab-testing/test/merge_requests/" + mrID + "#note_" + commentID
203+
url := "https://gitlab.com/lab-testing/test/-/merge_requests/" + mrID + "#note_" + commentID
204204
require.Contains(t, out, url)
205205
})
206206
t.Run("show MR with comment", func(t *testing.T) {

cmd/snippet_browse.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ var snippetBrowseCmd = &cobra.Command{
3636
if global || rn == "" {
3737
hostURL.Path = path.Join(hostURL.Path, "dashboard", "snippets")
3838
} else {
39-
hostURL.Path = path.Join(hostURL.Path, rn, "snippets")
39+
hostURL.Path = path.Join(hostURL.Path, rn, "-", "snippets")
4040
}
4141

4242
if id > 0 {

cmd/snippet_browse_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ func Test_snippetBrowse(t *testing.T) {
2020
defer func() { browse = oldBrowse }()
2121

2222
browse = func(url string) error {
23-
require.Equal(t, "https://gitlab.com/zaquestion/test/snippets", url)
23+
require.Equal(t, "https://gitlab.com/zaquestion/test/-/snippets", url)
2424
return nil
2525
}
2626

2727
snippetBrowseCmd.Run(nil, []string{})
2828

2929
browse = func(url string) error {
30-
require.Equal(t, "https://gitlab.com/zaquestion/test/snippets/23", url)
30+
require.Equal(t, "https://gitlab.com/zaquestion/test/-/snippets/23", url)
3131
return nil
3232
}
3333

internal/gitlab/gitlab.go

+10-10
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ func MRCreateDiscussion(projID interface{}, id int, opts *gitlab.CreateMergeRequ
399399
if err != nil {
400400
return "", err
401401
}
402-
return fmt.Sprintf("%s/merge_requests/%d#note_%d", p.WebURL, note.NoteableIID, note.ID), nil
402+
return fmt.Sprintf("%s/-/merge_requests/%d#note_%d", p.WebURL, note.NoteableIID, note.ID), nil
403403
}
404404

405405
// MRUpdate edits an merge request on a GitLab project
@@ -437,7 +437,7 @@ func MRCreateNote(projID interface{}, id int, opts *gitlab.CreateMergeRequestNot
437437
if err != nil {
438438
return "", err
439439
}
440-
return fmt.Sprintf("%s/merge_requests/%d#note_%d", p.WebURL, note.NoteableIID, note.ID), nil
440+
return fmt.Sprintf("%s/-/merge_requests/%d#note_%d", p.WebURL, note.NoteableIID, note.ID), nil
441441
}
442442

443443
// MRGet retrieves the merge request from GitLab project
@@ -666,7 +666,7 @@ func IssueCreateNote(projID interface{}, id int, opts *gitlab.CreateIssueNoteOpt
666666
if err != nil {
667667
return "", err
668668
}
669-
return fmt.Sprintf("%s/issues/%d#note_%d", p.WebURL, note.NoteableIID, note.ID), nil
669+
return fmt.Sprintf("%s/-/issues/%d#note_%d", p.WebURL, note.NoteableIID, note.ID), nil
670670
}
671671

672672
// IssueGet retrieves the issue information from a GitLab project
@@ -1455,7 +1455,7 @@ func AddMRDiscussionNote(projID interface{}, mrID int, discussionID string, body
14551455
if err != nil {
14561456
return "", err
14571457
}
1458-
return fmt.Sprintf("%s/merge_requests/%d#note_%d", p.WebURL, note.NoteableIID, note.ID), nil
1458+
return fmt.Sprintf("%s/-/merge_requests/%d#note_%d", p.WebURL, note.NoteableIID, note.ID), nil
14591459
}
14601460

14611461
// AddIssueDiscussionNote adds a note to an existing issue discussion on GitLab
@@ -1473,7 +1473,7 @@ func AddIssueDiscussionNote(projID interface{}, issueID int, discussionID string
14731473
if err != nil {
14741474
return "", err
14751475
}
1476-
return fmt.Sprintf("%s/issues/%d#note_%d", p.WebURL, note.NoteableIID, note.ID), nil
1476+
return fmt.Sprintf("%s/-/issues/%d#note_%d", p.WebURL, note.NoteableIID, note.ID), nil
14771477
}
14781478

14791479
// UpdateIssueDiscussionNote updates a specific discussion or note in the
@@ -1492,7 +1492,7 @@ func UpdateIssueDiscussionNote(projID interface{}, issueID int, discussionID str
14921492
if err != nil {
14931493
return "", err
14941494
}
1495-
return fmt.Sprintf("%s/issues/%d#note_%d", p.WebURL, note.NoteableIID, note.ID), nil
1495+
return fmt.Sprintf("%s/-/issues/%d#note_%d", p.WebURL, note.NoteableIID, note.ID), nil
14961496
}
14971497

14981498
// UpdateMRDiscussionNote updates a specific discussion or note in the
@@ -1511,7 +1511,7 @@ func UpdateMRDiscussionNote(projID interface{}, mrID int, discussionID string, n
15111511
if err != nil {
15121512
return "", err
15131513
}
1514-
return fmt.Sprintf("%s/merge_requests/%d#note_%d", p.WebURL, note.NoteableIID, note.ID), nil
1514+
return fmt.Sprintf("%s/-/merge_requests/%d#note_%d", p.WebURL, note.NoteableIID, note.ID), nil
15151515
}
15161516

15171517
// ListMRsClosingIssue returns a list of MR IDs that has relation to an issue
@@ -1581,7 +1581,7 @@ func MoveIssue(projID interface{}, id int, destProjID interface{}) (string, erro
15811581
return "", err
15821582
}
15831583

1584-
return fmt.Sprintf("%s/issues/%d", destProject.WebURL, issue.IID), nil
1584+
return fmt.Sprintf("%s/-/issues/%d", destProject.WebURL, issue.IID), nil
15851585
}
15861586

15871587
// GetMRApprovalsConfiguration returns the current MR approval rule
@@ -1609,7 +1609,7 @@ func ResolveMRDiscussion(projID interface{}, mrID int, discussionID string, note
16091609
if err != nil {
16101610
return "", err
16111611
}
1612-
return fmt.Sprintf("Resolved %s/merge_requests/%d#note_%d", p.WebURL, mrID, noteID), nil
1612+
return fmt.Sprintf("Resolved %s/-/merge_requests/%d#note_%d", p.WebURL, mrID, noteID), nil
16131613
}
16141614

16151615
// TodoList retuns a list of *gitlab.Todo refering to user's Todo list
@@ -1837,7 +1837,7 @@ func CreateMergeRequestCommitDiscussion(projID interface{}, id int, sha string,
18371837
if err != nil {
18381838
return "", err
18391839
}
1840-
return fmt.Sprintf("%s/merge_requests/%d#note_%d", p.WebURL, note.NoteableIID, note.ID), nil
1840+
return fmt.Sprintf("%s/-/merge_requests/%d#note_%d", p.WebURL, note.NoteableIID, note.ID), nil
18411841
}
18421842

18431843
// hasNextPage get the next page number in case the API response has more

0 commit comments

Comments
 (0)