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 d57d5ec
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 33 deletions.
27 changes: 16 additions & 11 deletions .github/workflows/release-process.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -94,17 +94,17 @@ 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
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: 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: 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 @@ -125,3 +125,8 @@ jobs:
pull_number: prNumber,
body: updatedBody
});
await github.rest.pulls.enableAutoMerge({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: prNumber
});
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 d57d5ec

Please sign in to comment.