Repository navigation
GH-55475: [Dev] Use merge button instead of merge script #55484
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
Open
rok
wants to merge
1
commit into
apache:main
Choose a base branch
from
rok:gh-55475-merge-button
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+577
−18
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| // Licensed to the Apache Software Foundation (ASF) under one | ||
| // or more contributor license agreements. See the NOTICE file | ||
| // distributed with this work for additional information | ||
| // regarding copyright ownership. The ASF licenses this file | ||
| // to you under the Apache License, Version 2.0 (the | ||
| // "License"); you may not use this file except in compliance | ||
| // with the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
|
|
||
|
|
||
| const helpers = require("./helpers.js"); | ||
|
|
||
| // GH-XXX: [Component] Title or MINOR: [Component] Title | ||
| const TITLE_PATTERN = /^(?:GH-(\d+)|MINOR): (?:\[[^\]]+\])+ \S/; | ||
|
|
||
| /** | ||
| * Checks whether the pull request can be merged with the merge | ||
| * button: | ||
| * - The title is "GH-XXX: [Component] Title" or | ||
| * "MINOR: [Component] Title". It's used as the commit title. | ||
| * - The issue in the title exists and is open. It's closed by | ||
| * merged.js on merge. | ||
| * - The issue is assigned to someone. issue_check.js assigns it to | ||
| * the pull request author if possible. | ||
| * | ||
| * @param {Object} github | ||
| * @param {Object} context | ||
| * @returns {String[]} The found problems. | ||
| */ | ||
| async function check(github, context) { | ||
| const title = context.payload.pull_request.title; | ||
| const matched = TITLE_PATTERN.exec(title); | ||
| if (!matched) { | ||
| return [ | ||
| `The title must be "GH-XXX: [Component] Title" or ` + | ||
| `"MINOR: [Component] Title": ${title}`, | ||
| ]; | ||
| } | ||
| const issueID = matched[1]; | ||
| if (!issueID) { | ||
| return []; | ||
| } | ||
|
|
||
| const issueInfo = await helpers.getGitHubInfo( | ||
| github, context, issueID, context.payload.number); | ||
| if (!issueInfo) { | ||
| return [`GitHub issue #${issueID} could not be retrieved.`]; | ||
| } | ||
| if (issueInfo.pull_request) { | ||
| return [`#${issueID} is a pull request, not an issue.`]; | ||
| } | ||
| const errors = []; | ||
| if (issueInfo.state !== "open") { | ||
| errors.push(`GitHub issue #${issueID} is already closed.`); | ||
| } | ||
| if (!issueInfo.assignees.length) { | ||
| errors.push(`GitHub issue #${issueID} is not assigned to anyone.`); | ||
| } | ||
| return errors; | ||
| } | ||
|
|
||
| module.exports = async ({github, context, core}) => { | ||
| // The "Dev PR" workflow assigns the issue at the same time. Wait | ||
| // for it. | ||
| let errors = await check(github, context); | ||
| for (let i = 0; i < 6 && errors.length > 0 && | ||
| TITLE_PATTERN.test(context.payload.pull_request.title); i++) { | ||
| await new Promise((resolve) => setTimeout(resolve, 10 * 1000)); | ||
| errors = await check(github, context); | ||
| } | ||
| if (errors.length > 0) { | ||
| core.setFailed(errors.join("\n")); | ||
| } | ||
| }; | ||
| module.exports.check = check; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,216 @@ | ||
| // Licensed to the Apache Software Foundation (ASF) under one | ||
| // or more contributor license agreements. See the NOTICE file | ||
| // distributed with this work for additional information | ||
| // regarding copyright ownership. The ASF licenses this file | ||
| // to you under the Apache License, Version 2.0 (the | ||
| // "License"); you may not use this file except in compliance | ||
| // with the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
|
|
||
| const helpers = require("./helpers.js"); | ||
|
|
||
| const VERSION_PATTERN = /^\d+\.\d+\.\d+$/; | ||
|
|
||
| /** | ||
| * Compares two versions like "23.0.0" numerically. | ||
| * | ||
| * @param {String} a | ||
| * @param {String} b | ||
| * @returns {Number} negative if a < b, positive if a > b, 0 otherwise. | ||
| */ | ||
| function compareVersions(a, b) { | ||
| const aParts = a.split(".").map(Number); | ||
| const bParts = b.split(".").map(Number); | ||
| for (let i = 0; i < aParts.length; i++) { | ||
| if (aParts[i] !== bParts[i]) { | ||
| return aParts[i] - bParts[i]; | ||
| } | ||
| } | ||
| return 0; | ||
| } | ||
|
|
||
| /** | ||
| * Chooses the version a pull request merged into main is released in. | ||
| * This mirrors get_candidate_fix_version() in dev/merge_arrow_pr.py. | ||
| * | ||
| * @param {Array<String>} versions - The titles of the open milestones. | ||
| * @param {Array<String>} maintenanceBranches - The maint-X.Y.Z branches. | ||
| * @returns {String} the version or null if no version can be chosen. | ||
| */ | ||
| function detectFixVersion(versions, maintenanceBranches) { | ||
| versions = versions.filter((version) => VERSION_PATTERN.test(version)); | ||
| const majorVersions = versions.filter((version) => version.endsWith(".0.0")); | ||
| if (versions.length > majorVersions.length) { | ||
| // If there is a future major release, suggest that | ||
| versions = majorVersions; | ||
| } | ||
| versions = versions | ||
| .filter((version) => !maintenanceBranches.includes(`maint-${version}`)) | ||
| .sort(compareVersions); | ||
| return versions.length > 0 ? versions[0] : null; | ||
| } | ||
|
|
||
| /** | ||
| * Removes the PR workflow state labels from the merged pull request. | ||
| * | ||
| * @param {Object} github | ||
| * @param {Object} context | ||
| * @param {Object} pullRequest | ||
| */ | ||
| async function clearStateLabels(github, context, pullRequest) { | ||
| for (const label of pullRequest.labels) { | ||
| // All PR workflow state labels starts with "awaiting" | ||
| if (!label.name.startsWith("awaiting")) { | ||
| continue; | ||
| } | ||
| try { | ||
| await github.rest.issues.removeLabel({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: pullRequest.number, | ||
| name: label.name | ||
| }); | ||
| } catch (error) { | ||
| // The label may be already removed. | ||
| if (error.status !== 404) { | ||
| throw error; | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Assigns the milestone of the release the pull request is part of to the | ||
| * GitHub Issue. It's the milestone of the pull request if it has one. | ||
| * Otherwise an already assigned milestone is kept or the next major | ||
| * release is used. | ||
| * | ||
| * @param {Object} github | ||
| * @param {Object} context | ||
| * @param {Object} pullRequest | ||
| * @param {Object} issueInfo | ||
| */ | ||
| async function assignMilestone(github, context, pullRequest, issueInfo) { | ||
| if (pullRequest.milestone) { | ||
| if (issueInfo.milestone?.number !== pullRequest.milestone.number) { | ||
| await github.rest.issues.update({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: issueInfo.number, | ||
| milestone: pullRequest.milestone.number | ||
| }); | ||
| } | ||
| return; | ||
| } | ||
| if (issueInfo.milestone) { | ||
| return; | ||
| } | ||
| const milestones = await github.paginate(github.rest.issues.listMilestones, { | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| state: "open", | ||
| per_page: 100 | ||
| }); | ||
| const branches = await github.paginate(github.rest.repos.listBranches, { | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| per_page: 100 | ||
| }); | ||
| const fixVersion = detectFixVersion( | ||
| milestones.map((milestone) => milestone.title), | ||
| branches | ||
| .map((branch) => branch.name) | ||
| .filter((name) => name.startsWith("maint-"))); | ||
| if (!fixVersion) { | ||
| console.log(`No milestone found for GitHub issue #${issueInfo.number}`); | ||
| return; | ||
| } | ||
| await github.rest.issues.update({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: issueInfo.number, | ||
| milestone: milestones.find((milestone) => milestone.title === fixVersion).number | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * Closes the GitHub Issue and comments which pull request resolved it | ||
| * after that. GitHub may have closed the issue already if the pull | ||
| * request description has "Closes #XXX". | ||
| * | ||
| * @param {Object} github | ||
| * @param {Object} context | ||
| * @param {Object} pullRequest | ||
| * @param {Object} issueInfo | ||
| */ | ||
| async function closeGitHubIssue(github, context, pullRequest, issueInfo) { | ||
| const issue = { | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: issueInfo.number, | ||
| }; | ||
| if (issueInfo.state !== "closed") { | ||
| await github.rest.issues.update({...issue, state: "closed"}); | ||
| } | ||
| // The merge script may have added the same comment. | ||
| const body = `Issue resolved by pull request ${pullRequest.number}\n${pullRequest.html_url}`; | ||
| const comments = await github.paginate( | ||
| github.rest.issues.listComments, {...issue, per_page: 100}); | ||
| if (comments.some((comment) => comment.body === body)) { | ||
| return; | ||
| } | ||
| await github.rest.issues.createComment({...issue, body}); | ||
| } | ||
|
|
||
| /** | ||
| * Does what is needed after a pull request is merged. | ||
| * | ||
| * @param {Object} github | ||
| * @param {Object} context | ||
| * @param {Object} pullRequest | ||
| */ | ||
| async function resolve(github, context, pullRequest) { | ||
| await clearStateLabels(github, context, pullRequest); | ||
| const issue = helpers.detectIssue(pullRequest.title); | ||
| if (!issue || issue.kind !== "github") { | ||
| return; | ||
| } | ||
| const issueInfo = await helpers.getGitHubInfo(github, context, issue.id, pullRequest.number); | ||
| if (!issueInfo) { | ||
| throw new Error(`GitHub issue #${issue.id} could not be retrieved.`); | ||
| } | ||
| await assignMilestone(github, context, pullRequest, issueInfo); | ||
| await closeGitHubIssue(github, context, pullRequest, issueInfo); | ||
| } | ||
|
|
||
| /** | ||
| * This is for pushes to main. A pushed commit that isn't the merge | ||
| * commit of a pull request (e.g. a version bump by a release manager) | ||
| * is ignored. | ||
| */ | ||
| module.exports = async ({github, context}) => { | ||
| for (const commit of context.payload.commits) { | ||
| const {data: pullRequests} = | ||
| await github.rest.repos.listPullRequestsAssociatedWithCommit({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| commit_sha: commit.id | ||
| }); | ||
| for (const pullRequest of pullRequests) { | ||
| if (pullRequest.merge_commit_sha === commit.id) { | ||
| await resolve(github, context, pullRequest); | ||
| } | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| module.exports.detectFixVersion = detectFixVersion; | ||
| module.exports.resolve = resolve; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| # Licensed to the Apache Software Foundation (ASF) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. The ASF licenses this file | ||
| # to you under the Apache License, Version 2.0 (the | ||
| # "License"); you may not use this file except in compliance | ||
| # with the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, | ||
| # software distributed under the License is distributed on an | ||
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| # KIND, either express or implied. See the License for the | ||
| # specific language governing permissions and limitations | ||
| # under the License. | ||
|
|
||
| name: Dev PR merge check | ||
|
|
||
| on: | ||
| pull_request: | ||
| branches: | ||
| - main | ||
| types: | ||
| - opened | ||
| - edited | ||
| - reopened | ||
| - synchronize | ||
|
|
||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ github.repository }}-${{ github.event.number }} | ||
| cancel-in-progress: true | ||
|
|
||
| permissions: | ||
| contents: read | ||
| issues: read | ||
|
|
||
| jobs: | ||
| merge-check: | ||
| # This is a required status check of the main branch in | ||
| # .asf.yaml: the merge button is disabled while this fails. Re-run | ||
| # this job after you fix the issue (e.g. assign it) because | ||
| # changes of the issue don't trigger this workflow. | ||
| name: Merge check | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v7 | ||
| with: | ||
| persist-credentials: false | ||
| sparse-checkout: .github/workflows/dev_pr | ||
|
|
||
| - name: Check title and issue | ||
| uses: actions/github-script@v9 | ||
| with: | ||
| github-token: ${{ secrets.GITHUB_TOKEN }} | ||
| script: | | ||
| const script = require(`${process.env.GITHUB_WORKSPACE}/.github/workflows/dev_pr/merge_check.js`); | ||
| await script({github, context, core}); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.