Skip to content

Commit

Permalink
Merge pull request #446 from sue445/feature/snippet_hyphen_path
Browse files Browse the repository at this point in the history
Support snippet routes including `/-/` for GitLab 13.3.0+
  • Loading branch information
sue445 authored Oct 25, 2020
2 parents e0148a6 + d9aa88a commit 1b39e8b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion gitlab/snippet_fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type snippetFetcher struct {
}

func (f *snippetFetcher) fetchPath(path string, client *gitlab.Client, isDebugLogging bool) (*Page, error) {
re := regexp.MustCompile("^snippets/(\\d+)")
re := regexp.MustCompile("^(?:-/)?snippets/(\\d+)")
matched := re.FindStringSubmatch(path)

if matched == nil {
Expand Down
18 changes: 18 additions & 0 deletions gitlab/url_parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,24 @@ func TestGitlabUrlParser_FetchURL(t *testing.T) {
Color: "",
},
},
{
name: "Snippet URL (including /-/)",
args: args{
url: "http://example.com/-/snippets/3",
},
want: &Page{
Title: "add.rb",
Description: "```\nputs 'Hello'\n```",
AuthorName: "John Smith",
AuthorAvatarURL: "",
AvatarURL: "",
CanTruncateDescription: false,
FooterTitle: "",
FooterURL: "",
FooterTime: tp(time.Date(2012, 6, 28, 10, 52, 4, 0, time.UTC)),
Color: "",
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit 1b39e8b

Please sign in to comment.