Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update PR to enable automerge after realease setup #3567

Merged
merged 2 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Loading