terminus icon indicating copy to clipboard operation
terminus copied to clipboard

Bitbucket Client error: for "terminus -v build:env:delete:pr "$TERMINUS_SITE" --yes"

Open vrajannagari opened this issue 3 years ago • 6 comments

Platform

( ) MacOS ( ) Linux ( ) Winderz

Installed Via

( ) Homebrew ( ) Apt Package ( ) Manually

PHP Version

( ) 7.4x ( ) 8.0 ( ) 8.1

Command Executed

"terminus -v build:env:delete:pr "$TERMINUS_SITE" --yes"

Expected behavior

I had expected for the command to check the pull requests and if they are merged delete the multi-dev environment from Pantheon.

Actual behavior

Getting a client error saying unauthorized even though the token is set as secret

[notice] Call Bitbucket API: GET repositories/{org}/{repo}/pullrequests?state=MERGED%26state%3DDECLINED%26state%3DSUPERSEDED%26state%3DOPEN [error] Client error: GET https://api.bitbucket.org/2.0/repositories/{org}/{repo}/pullrequests?state=MERGED%26state%3DDECLINED%26state%3DSUPERSEDED%26state%3DOPEN resulted in a 401 Unauthorized response

vrajannagari avatar Mar 02 '22 20:03 vrajannagari

Kind of disheartening that there hasn't been a response to this issue. It's completely derailed some of our build processes and now we have to go in and manually delete several multidev environments in order for our build to pass.

JDDoesDev avatar Jun 21 '22 19:06 JDDoesDev

I created an internal ticket, https://getpantheon.atlassian.net/browse/CMS-753, to track this. If you encounter bugs that are interfering with your development workflow, submitting a support request will generally be higher visibility than reporting through GitHub, especially if you have a support contract.

greg-1-anderson avatar Jun 21 '22 20:06 greg-1-anderson

One thing that comes to mind, though, is to ensure that the token that you've set has the right roles to delete PRs. That is one thing that could cause this symptom.

greg-1-anderson avatar Jun 21 '22 20:06 greg-1-anderson

Thanks, @greg-1-anderson. It's always great to see an issue being addressed by you. This has been an issue since 3/1/2022 when Bitbucket changed their API. The error

 [error]  Client error: `GET https://api.bitbucket.org/2.0/repositories/myrepo/myproject/pullrequests?state=MERGED%26state%3DDECLINED%26state%3DSUPERSEDED%26state%3DOPEN` resulted in a `401 Unauthorized` response 

looks like it's not trying to delete the PRs, but get a list.

I believe that the issue itself is from within https://github.com/pantheon-systems/terminus-build-tools-plugin since the command throwing the error is defined in that addon, however I found this issue was created and I did not want to create a duplicate issue

JDDoesDev avatar Jun 22 '22 13:06 JDDoesDev

Ah, great, that's good info. We'll assign someone to look at this and update the API call.

greg-1-anderson avatar Jun 22 '22 15:06 greg-1-anderson

@greg-1-anderson Have there been any updates to this or an issue that can be linked back to this one?

JDDoesDev avatar Aug 04 '22 15:08 JDDoesDev

Opened per support recommendation.

ozheller-nerd avatar May 23 '23 16:05 ozheller-nerd

Hi!

A super delayed but important update on this: in the ticket Greg mentioned above, we did some investigation and found that the issue was missing permissions on the App Password. We documented this in https://docs.pantheon.io/guides/build-tools/create-project/#access-tokens-optional

I just replied to @ozheller-nerd in the new issue in the build tools plugin.

I'm going ahead and close this issue; feel free to reopen/open a new one in terminus-build-tools if you still have related issues

kporras07 avatar May 23 '23 21:05 kporras07