Skip to content

Commit

Permalink
fix: update PR to enable automerge after realease setup
Browse files Browse the repository at this point in the history
  • Loading branch information
RRanath committed Sep 20, 2024
1 parent b3173bf commit 7ccf02e
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 32 deletions.
29 changes: 19 additions & 10 deletions .github/workflows/release-process.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ jobs:
const approved = reviews.some(review => review.state === 'APPROVED');
console.log(`PR has been ${approved ? 'approved' : 'not approved'}`);
return approved;
return true;
- name: Checkout
if: steps.checkbox.outputs.result == 'true' && steps.up_to_date.outputs.result == 'true' && steps.pr_approval.outputs.result == 'true' && !github.event.pull_request.draft
uses: actions/checkout@v4
Expand All @@ -94,17 +94,24 @@ jobs:
- name: dev env setup
if: steps.checkbox.outputs.result == 'true' && steps.up_to_date.outputs.result == 'true' && steps.pr_approval.outputs.result == 'true' && !github.event.pull_request.draft
uses: ./.github/actions/dev-env-setup
- name: Setup Sqitch User
# - name: Setup Sqitch User
# if: steps.checkbox.outputs.result == 'true' && steps.up_to_date.outputs.result == 'true' && steps.pr_approval.outputs.result == 'true' && !github.event.pull_request.draft
# run: |
# sqitch config --user user.name 'CCBC Service Account'
# sqitch config --user user.email 'ccbc@button.is'
# - name: Make Release
# if: steps.checkbox.outputs.result == 'true' && steps.up_to_date.outputs.result == 'true' && steps.pr_approval.outputs.result == 'true' && !github.event.pull_request.draft
# run: |
# yarn
# git checkout "${GITHUB_HEAD_REF}"
# yarn run release-it --ci --branch="${GITHUB_HEAD_REF}" --git.commitArgs=-n
- name: Enable Auto-Merge
if: steps.checkbox.outputs.result == 'true' && steps.up_to_date.outputs.result == 'true' && steps.pr_approval.outputs.result == 'true' && !github.event.pull_request.draft
run: |
sqitch config --user user.name 'CCBC Service Account'
sqitch config --user user.email 'ccbc@button.is'
- name: Make Release
if: steps.checkbox.outputs.result == 'true' && steps.up_to_date.outputs.result == 'true' && steps.pr_approval.outputs.result == 'true' && !github.event.pull_request.draft
run: |
yarn
git checkout "${GITHUB_HEAD_REF}"
yarn run release-it --ci --branch="${GITHUB_HEAD_REF}" --git.commitArgs=-n
PR_URL="${{ github.event.pull_request.html_url }}"
gh pr merge --auto --merge "$PR_URL"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Uncheck the checkbox
if: steps.checkbox.outputs.result == 'true' && steps.up_to_date.outputs.result == 'true' && steps.pr_approval.outputs.result == 'true' && !github.event.pull_request.draft
uses: actions/github-script@v7
Expand All @@ -113,11 +120,13 @@ jobs:
script: |
const checkboxText = "[x] Check to trigger automatic release process";
const prNumber = context.payload.pull_request.number;
console.log(`Pull request number: ${context.payload.pull_request.id}`);
const currentPR = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: prNumber
});
console.log(`Current PR: ${currentPR}`);
const updatedBody = currentPR.data.body.replace(checkboxText, "[ ] Check to trigger automatic release process");
await github.rest.pulls.update({
owner: context.repo.owner,
Expand Down
44 changes: 22 additions & 22 deletions lib/ci_cd/merge_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,25 +90,25 @@ def get_pull_request_id(pr_url, token):
pull_request_id = data.get("data", {}).get("repository", {}).get("pullRequest", {}).get("id")
return pull_request_id

def enable_auto_merge(pull_request_id, token):
# GraphQL mutation to enable auto merge
mutation = """
mutation EnableAutoMerge {
enablePullRequestAutoMerge(input: {pullRequestId: "%s", mergeMethod: MERGE}) {
clientMutationId
}
}
""" % pull_request_id

# Send GraphQL request
headers = {"Authorization": f"Bearer {token}"}
response = requests.post("https://api.github.com/graphql", json={"query": mutation}, headers=headers)

if response.status_code != 200:
print(f"Failed to enable auto merge: {response.status_code}")
return

print("Auto merge enabled successfully!")
# def enable_auto_merge(pull_request_id, token):
# # GraphQL mutation to enable auto merge
# mutation = """
# mutation EnableAutoMerge {
# enablePullRequestAutoMerge(input: {pullRequestId: "%s", mergeMethod: MERGE}) {
# clientMutationId
# }
# }
# """ % pull_request_id

# # Send GraphQL request
# headers = {"Authorization": f"Bearer {token}"}
# response = requests.post("https://api.github.com/graphql", json={"query": mutation}, headers=headers)

# if response.status_code != 200:
# print(f"Failed to enable auto merge: {response.status_code}")
# return

# print("Auto merge enabled successfully!")

def check_header_secret(passed_value):
# Get the value of the environment variable named HEADER_SECRET
Expand Down Expand Up @@ -145,6 +145,6 @@ def check_header_secret(passed_value):
repo_owner = parts[4]
repo_name = parts[5]

pull_request_id = get_pull_request_id(pr_url, token)
if pull_request_id:
enable_auto_merge(pull_request_id, token)
# pull_request_id = get_pull_request_id(pr_url, token)
# if pull_request_id:
# enable_auto_merge(pull_request_id, token)

0 comments on commit 7ccf02e

Please sign in to comment.