Skip to content

Commit

Permalink
Fix initialization of GitLab repos
Browse files Browse the repository at this point in the history
GitLab returns `404` on a `repository/tree` call if the repo has zero commits.
We checked against the error message but the client library started to return a static `404` error which makes our check fail.

This commit changes the checking logic to check for the clients static `ErrNotFound` error. This might catch other errors too (repo does not exists at all), but those errors will be caught in the next step.
  • Loading branch information
bastjan committed Jul 30, 2024
1 parent 7b27efd commit dfd7675
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 2 additions & 1 deletion git/gitlab/gitlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,8 @@ func (g *Gitlab) compareFiles() ([]manager.CommitFile, error) {
if err != nil {
// if the tree is not found it's probably just because there are no files at all currently...
// So we have to apply all pending ones.
if strings.Contains(err.Error(), "Tree Not Found") {
if errors.Is(err, gitlab.ErrNotFound) {
g.log.Info("ListTree got 404; most likely no files found in repository, applying all pending files")

for name, content := range g.ops.TemplateFiles {
if content != manager.DeletionMagicString {
Expand Down
2 changes: 1 addition & 1 deletion git/gitlab/gitlab_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ func testGetCommitServer(t *testing.T, files []string) *httptest.Server {

mux.HandleFunc("/api/v4/projects/3/repository/tree", func(res http.ResponseWriter, req *http.Request) {
if len(files) == 0 {
_, _ = res.Write([]byte(`[]`))
res.WriteHeader(http.StatusNotFound)
return
}

Expand Down

0 comments on commit dfd7675

Please sign in to comment.