renovatebot / renovate

Home of the Renovate CLI: Cross-platform Dependency Automation by Mend.io
https://mend.io/renovate
GNU Affero General Public License v3.0
17.17k stars 2.24k forks source link

Renovate bailing on branches that are not mergeable and need rebasing on Gitlab #1992

Closed ghost closed 6 years ago

ghost commented 6 years ago

What Renovate type are you using? Renovate CLI

Describe the bug Renovate generated a MR for an upgrade and with bumpVersion active it bumped the version from 0.1.0 to 0.1.1 in the MR. After manually messing around by changing the version to 0.2.0 in the master branch Renovate recognizes the previous branch needs a rebase, closes the MR and errors with the following log output:

 INFO: Branch has 1 upgrade(s) (repository=*/renovate-test, dependencies=typescript, branch=renovate/typescript-2.x)
 INFO: Branch already exists (repository=*/renovate-test, dependencies=typescript, branch=renovate/typescript-2.x)
 INFO: Branch is not mergeable and needs rebasing (repository=*/renovate-test, dependencies=typescript, branch=renovate/typescript-2.x)
 INFO: Deleting unmergeable branch in order to recreate/rebase (repository=*/renovate-test, dependencies=typescript, branch=renovate/typescript-2.x)
 INFO: Bumped package.json version (repository=*/renovate-test, dependencies=typescript, branch=renovate/typescript-2.x)
ERROR: Error updating branch: 404 Branch Not Found (404) (repository=*/renovate-test, dependencies=typescript, branch=renovate/typescript-2.x)
       "err": {
         "name": "GitLabError",
         "host": "gitlab.com",
         "hostname": "gitlab.com",
         "method": "DELETE",
         "path": "/api/v4/projects/*%2Frenovate-test/repository/branches/renovate%2Ftypescript-2.x",
         "protocol": "https:",
         "url": "https://gitlab.com/api/v4/projects/*%2Frenovate-test/repository/branches/renovate%2Ftypescript-2.x",
         "statusCode": 404,
         "statusMessage": "Not Found",
         "headers": {
           "server": "nginx",
           "date": "Sat, 19 May 2018 09:38:47 GMT",
           "content-type": "application/json",
           "content-length": "34",
           "connection": "close",
           "cache-control": "no-cache",
           "vary": "Origin",
           "x-content-type-options": "nosniff",
           "x-frame-options": "SAMEORIGIN",
           "x-request-id": "914281ba-3a00-4164-a340-88b6387d47ba",
           "x-runtime": "0.124542",
           "ratelimit-limit": "600",
           "ratelimit-observed": "5",
           "ratelimit-remaining": "595",
           "ratelimit-reset": "1526722787",
           "ratelimit-resettime": "Sun, 19 May 2018 09:39:47 GMT"
         }
       }

It seems that Renovate and Gitlab are messing around with closing/deleting branches. After this issue the branch has been deleted but the MR has only been closed. So it seems Renovate is trying to update a branch that it has just deleted.

To Reproduce Steps to reproduce the behavior:

  1. Create repository with a package.json of version: "0.1.0" and any outdated package e.g. "typescript": "2.7.1".
  2. Run onboarding and configuration with "bumpVersion": "patch" in renovate.json.
  3. Now Renovate should've created a MR to update typescript to version 2.8.3 (at the time of this post) and suggests version: "0.1.1" in the package.json of the renovate/typescript-2.X branch.
  4. Fake a minor upgrade by manually setting version: "0.2.0" in the package.json of the master branch.
  5. Run Renovate again and the log output from above will be visible.

Expected behavior I'd expect that the old MR either gets closed or deleted (on Gitlab that is actually possible) and that renovate/typescript-2.X gets either rebased or deleted and recreated from the master branch with the suggested upgrade to typescript and a version bump to version: "0.2.1" in the package.json.

Additional context Minor edit: running Renovate a second time after the error does not recreate the branch or the MR since it reports that a "Closed PR already exists. Skipping branch." which is not the desired behaviour in that case. Apparently it thinks someone declined the upgrade and thus does not want to be noisy.

rarkins commented 6 years ago

GitLab changing their APIs has been a real challenge. Earlier, they allowed a branch to be deleted without closing the MR - so we would delete then create again and all was stitched together. They changed logic to then close MRs automatically if the branch was deleted, but I found you could still recreate the branch and reopen the PR, so it wasn’t too bad/noisy. Creating a new PR would be undesirable for most as you create a lot of noise and lose comment histories too. Seems like creating the new branch failed somehow and that’s why we’re left with a blocking PR. I’ll look into it soon

rarkins commented 6 years ago

BTW if you rename the old MR then it still unblock it and you should get a new MR

ghost commented 6 years ago

Unfortunately I cannot test renaming the previous MR anymore since that was a test repository I already deleted. Once it happens in my current real repository without a fix from your end I will give it a try.

renovate-bot commented 6 years ago

:tada: This issue has been resolved in version 12.30.16 :tada:

The release is available on:

Your semantic-release bot :package::rocket: