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 f16a726
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 51 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/release-process.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,13 @@ jobs:
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: |
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 Down
51 changes: 0 additions & 51 deletions lib/ci_cd/merge_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,53 +63,6 @@ def update_pr_description(pr_url, token):
else:
print(f"Failed to update PR description: {response.status_code}")

def get_pull_request_id(pr_url, token):
# Extract pull request number from the URL
pr_number = pr_url.split("/")[-1]

# GraphQL query to get pull request ID
query = """
query GetPullRequestID {
repository(owner: "%s", name: "%s") {
pullRequest(number: %s) {
id
}
}
}
""" % (repo_owner, repo_name, pr_number)

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

if response.status_code != 200:
print(f"Failed to retrieve pull request ID: {response.status_code}")
return None

data = response.json()
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 check_header_secret(passed_value):
# Get the value of the environment variable named HEADER_SECRET
header_secret = os.environ.get('HEADER_SECRET')
Expand Down Expand Up @@ -144,7 +97,3 @@ def check_header_secret(passed_value):
parts = pr_url.split("/")
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)

0 comments on commit f16a726

Please sign in to comment.