This is my first foray into bitbucket pipelines.
In summary, when a pull request is created, I want a pipeline to decline the PR if it has no changes and merge the PR if there are changes. And only target source branches starting with a specific name.
Basically, the curl API calls do not work, they appear to return nothing. I have also tried using bearer token authorization where I created an Access token in the repository settings and copied that token into a repository variable and used that variable.
Is there a git command I could use to decline/merge the PR without credentials/API?
Hopefully the YML content renders correctly.
Thanks in advance for your help.
pull-requests: '**': - step: name: Check PR Source Branch script: - if [[ ! $BITBUCKET_BRANCH == blah-* ]]; then echo "Skipping PR not from blah branch"; exit 0; fi - step: name: Check for Changes script: - git fetch origin $BITBUCKET_PR_DESTINATION_BRANCH - git diff --exit-code origin/$BITBUCKET_PR_DESTINATION_BRANCH || echo "Changes detected" - if git diff --exit-code origin/$BITBUCKET_PR_DESTINATION_BRANCH; then echo "No changes detected, declining PR"; RESPONSE=$(curl -X POST -u $BITBUCKET_USERNAME:$BITBUCKET_APP_PASSWORD https://api.bitbucket.org/2.0/repositories/$BITBUCKET_REPO_OWNER/$BITBUCKET_REPO_SLUG/pullrequests/$BITBUCKET_PR_ID/decline) echo "RESPONSE = [$RESPONSE]" exit 1; fi - step: name: Merge PR script: - echo "Changes detected, merging PR"; - RESPONSE=$(curl -X POST -u $BITBUCKET_USERNAME:$BITBUCKET_APP_PASSWORD https://api.bitbucket.org/2.0/repositories/$BITBUCKET_REPO_OWNER/$BITBUCKET_REPO_SLUG/pullrequests/$BITBUCKET_PR_ID/merge) - echo "RESPONSE = [$RESPONSE]"
Solved now. I needed to set up an app password in my personal settings in bitbucket then create BITBUCKET_USERNAME and BITBUCKET_APP_PASSWORD repository variables, using the newly created app password from personal settings in BITBUCKET_APP_PASSWORD and the target bitbucket username in BITBUCKET_USERNAME.
G'day, @John Warde
I'm curious why you need to decline a pull request without any changes, as it's typically not possible to create a PR without modifications. Could you provide more context on this situation so I can offer more accurate advice
Regards,
Syahrul
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It is possible through automation. An external service, providing translations into PHP language files, creates an empty PR when there are no differences between the existing language files in the repo and what the external service has in store for our application language strings.
The root of the problem is, how do correctly authenticate the curl https://api.bitbucket.org/ API calls in a bitbucket pipeline? What type credential do I use? Is there any other setup I need to do outside of the pipeline i.e. in repository settings etc.. I am able to successfully execute the same API calls from my local machine but not within the bitbucket pipeline enironment.
Hopefully the indentation is correct now below ...
pull-requests:
'**':
- step:
name: Check PR Source Branch
script:
- if [[ ! $BITBUCKET_BRANCH == blah-* ]]; then echo "Skipping PR not from blah branch"; exit 0; fi
- step:
name: Check for Changes
script:
- git fetch origin $BITBUCKET_PR_DESTINATION_BRANCH
- git diff --exit-code origin/$BITBUCKET_PR_DESTINATION_BRANCH || echo "Changes detected"
- if git diff --exit-code origin/$BITBUCKET_PR_DESTINATION_BRANCH; then
echo "No changes detected, declining PR";
RESPONSE=$(curl -X POST -u $BITBUCKET_USERNAME:$BITBUCKET_APP_PASSWORD https://api.bitbucket.org/2.0/repositories/$BITBUCKET_REPO_OWNER/$BITBUCKET_REPO_SLUG/pullrequests/$BITBUCKET_PR_ID/decline)
echo "RESPONSE = [$RESPONSE]"
exit 1;
fi
- step:
name: Merge PR
script:
- echo "Changes detected, merging PR";
- RESPONSE=$(curl -X POST -u $BITBUCKET_USERNAME:$BITBUCKET_APP_PASSWORD https://api.bitbucket.org/2.0/repositories/$BITBUCKET_REPO_OWNER/$BITBUCKET_REPO_SLUG/pullrequests/$BITBUCKET_PR_ID/merge)
- echo "RESPONSE = [$RESPONSE]"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.