Skip to content

fix(gitlab): Use start_branch for file creation if branch doesn't exist already#4792

Merged
caarlos0 merged 10 commits intogoreleaser:mainfrom
baurmatt:fix-4543
Apr 23, 2024
Merged

fix(gitlab): Use start_branch for file creation if branch doesn't exist already#4792
caarlos0 merged 10 commits intogoreleaser:mainfrom
baurmatt:fix-4543

Conversation

@baurmatt
Copy link
Copy Markdown
Contributor

Creating files on a new branch is only possible with the API if start_branch
is given otherwise the API returns:

You can only create or edit files when you are on a branch

Fixes #4543

@pull-request-size pull-request-size Bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Apr 19, 2024
…xist already

Creating files on a new branch is only possible with the API if `start_branch`
is given otherwise the API returns:

> You can only create or edit files when you are on a branch

Fixes goreleaser#4543
@baurmatt baurmatt changed the title fix(gitlab): Use start_branch for file creation if branch doesn't exist already DRAFT: fix(gitlab): Use start_branch for file creation if branch doesn't exist already Apr 19, 2024
@baurmatt
Copy link
Copy Markdown
Contributor Author

Sorry, this doesn't work yet because the file existence check might return 404 but that's because the new branch doesn't exist already not the file itself :(

Having a fallback makes things way more complicated and doesn't really
work in a world where we have at least `master` and `main` commonly
used.
@baurmatt baurmatt changed the title DRAFT: fix(gitlab): Use start_branch for file creation if branch doesn't exist already fix(gitlab): Use start_branch for file creation if branch doesn't exist already Apr 19, 2024
@baurmatt
Copy link
Copy Markdown
Contributor Author

This turned out to be more complicated/bigger change than I've anticipated in the beginning. The problem was:

  • start_branch needs to be handle for update and create
  • Non existing branches need to be taken care of when checking if the file already exists
  • Hardcoded default branch fallback of master complicated the situation even more

Comment thread internal/client/gitlab.go Outdated
Copy link
Copy Markdown
Member

@caarlos0 caarlos0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you so much for this!

made a couple of small comments, mostly log messages!

Comment thread internal/client/gitlab.go Outdated
Comment thread internal/client/gitlab.go Outdated
Comment thread internal/client/gitlab.go Outdated
Comment thread internal/client/gitlab.go Outdated
Comment thread internal/client/gitlab.go Outdated
Comment thread internal/client/gitlab.go Outdated
Comment thread internal/client/gitlab.go Outdated
Comment thread internal/client/gitlab.go Outdated
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 19, 2024

Codecov Report

Attention: Patch coverage is 82.14286% with 10 lines in your changes are missing coverage. Please review.

Project coverage is 84.16%. Comparing base (c68d830) to head (f998b2a).
Report is 197 commits behind head on main.

❗ Current head f998b2a differs from pull request most recent head ffb961b. Consider uploading reports for the commit ffb961b to get more accurate results

Files Patch % Lines
internal/client/gitlab.go 82.14% 9 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4792      +/-   ##
==========================================
+ Coverage   83.77%   84.16%   +0.39%     
==========================================
  Files         135      137       +2     
  Lines       13029    11078    -1951     
==========================================
- Hits        10915     9324    -1591     
+ Misses       1677     1300     -377     
- Partials      437      454      +17     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@mavogel
Copy link
Copy Markdown
Member

mavogel commented Apr 21, 2024

Let me try got get a review done early next week here as well :)

baurmatt and others added 2 commits April 22, 2024 09:51
Co-authored-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
@baurmatt
Copy link
Copy Markdown
Contributor Author

@caarlos0 Thanks! :) I've applied all suggestions!

Looking forward to your review @mavogel! :)

@caarlos0 caarlos0 requested a review from mavogel April 22, 2024 13:11
Copy link
Copy Markdown
Member

@caarlos0 caarlos0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

second pass, a couple more small things

Comment thread internal/client/gitlab.go Outdated
Comment thread internal/client/gitlab.go Outdated
Comment thread internal/client/gitlab.go Outdated
baurmatt and others added 2 commits April 23, 2024 09:51
Co-authored-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
Comment thread internal/client/gitlab.go Outdated
@caarlos0 caarlos0 merged commit fd40f5d into goreleaser:main Apr 23, 2024
@github-actions github-actions Bot added this to the v1.26.0 milestone Apr 23, 2024
caarlos0 added a commit that referenced this pull request Apr 24, 2024
**Depends on #4792**

This adds support for opening pull requests on brew, krew, nix, scoop
and winget changes with Gitlab.

---------

Co-authored-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

gitlab: publish a brew formula throws an 400: "You can only create or edit files when you are on a branch" when creating brew formula

3 participants