-
Notifications
You must be signed in to change notification settings - Fork 96
GH-499: Require PR labels for changelog #594
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
Merged
Merged
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
add5d79
GH-499: Require PR labels for changelog
lidavidm a6b8e14
better automation
lidavidm 29c520c
configure changelog
lidavidm 27597b3
simplify template
lidavidm a6f52d9
issue comment
lidavidm df4cd4b
fix comment
lidavidm d4075c1
Update .github/workflows/dev_pr.yml
lidavidm ac75e64
Update CONTRIBUTING.md
lidavidm e46f293
Update CONTRIBUTING.md
lidavidm 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| ## What's Changed | ||
|
|
||
| Please fill in a description of the changes here. | ||
|
|
||
| **This contains breaking changes.** <!-- Remove this line if there are no breaking changes. --> | ||
|
|
||
| Closes #NNN. |
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,34 @@ | ||
| # 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. | ||
|
|
||
| changelog: | ||
| categories: | ||
| - title: Breaking Changes | ||
| labels: | ||
| - breaking-change | ||
|
|
||
| - title: New Features and Enhancements | ||
| labels: | ||
| - enhancement | ||
|
|
||
| - title: Bug Fixes | ||
| labels: | ||
| - bug-fix | ||
|
|
||
| - title: Other Changes | ||
| labels: | ||
| - "*" |
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,241 @@ | ||
| // 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. | ||
|
|
||
| async function have_comment(github, context, pr_number, tag) { | ||
| console.log(`Looking for existing comment on ${pr_number} with substring ${tag}`); | ||
| const query = ` | ||
| query($owner: String!, $name: String!, $number: Int!, $cursor: String) { | ||
| repository(owner: $owner, name: $name) { | ||
| pullRequest(number: $number) { | ||
| id | ||
| comments (after:$cursor, first: 50) { | ||
| nodes { | ||
| id | ||
| body | ||
| author { | ||
| login | ||
| } | ||
| } | ||
| pageInfo { | ||
| endCursor | ||
| hasNextPage | ||
| } | ||
| } | ||
| } | ||
| } | ||
| }`; | ||
| const tag_regexp = new RegExp(tag); | ||
|
|
||
| let cursor = null; | ||
| let pr_id = null; | ||
| while (true) { | ||
| const result = await github.graphql(query, { | ||
| owner: context.repo.owner, | ||
| name: context.repo.repo, | ||
| number: pr_number, | ||
| cursor, | ||
| }); | ||
| pr_id = result.repository.pullRequest.id; | ||
| cursor = result.repository.pullRequest.comments.pageInfo; | ||
| const comments = result.repository.pullRequest.comments.nodes; | ||
|
|
||
| for (const comment of comments) { | ||
| console.log(comment); | ||
| if (comment.author.login === "github-actions" && | ||
| comment.body.match(tag_regexp) !== null) { | ||
| console.log("Found existing comment"); | ||
| return {pr_id, comment_id: comment.id}; | ||
| } | ||
| } | ||
|
|
||
| if (!result.repository.pullRequest.comments.hasNextPage || | ||
| comments.length === 0) { | ||
| break; | ||
| } | ||
| } | ||
| console.log("No existing comment"); | ||
| return {pr_id, comment_id: null}; | ||
| } | ||
|
|
||
| async function upsert_comment(github, {pr_id, comment_id}, body, visible) { | ||
| console.log(`Upsert comment (pr_id=${pr_id}, comment_id=${comment_id}, visible=${visible})`); | ||
| if (!visible) { | ||
| if (comment_id === null) return; | ||
|
|
||
| const query = ` | ||
| mutation makeComment($comment: ID!) { | ||
| minimizeComment(input: {subjectId: $comment, classifier: RESOLVED}) { | ||
| clientMutationId | ||
| } | ||
| }`; | ||
| await github.graphql(query, { | ||
| comment: comment_id, | ||
| body, | ||
| }); | ||
| return; | ||
| } | ||
|
|
||
| if (comment_id === null) { | ||
| const query = ` | ||
| mutation makeComment($pr: ID!, $body: String!) { | ||
| addComment(input: {subjectId: $pr, body: $body}) { | ||
| clientMutationId | ||
| } | ||
| }`; | ||
| await github.graphql(query, { | ||
| pr: pr_id, | ||
| body, | ||
| }); | ||
| } else { | ||
| const query = ` | ||
| mutation makeComment($comment: ID!, $body: String!) { | ||
| unminimizeComment(input: {subjectId: $comment}) { | ||
| clientMutationId | ||
| } | ||
| updateIssueComment(input: {id: $comment, body: $body}) { | ||
| clientMutationId | ||
| } | ||
| }`; | ||
| await github.graphql(query, { | ||
| comment: comment_id, | ||
| body, | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| module.exports = { | ||
| check_title_format: function({core, github, context}) { | ||
| const title = context.payload.pull_request.title; | ||
| if (title.startsWith("MINOR: ")) { | ||
| context.log("PR is a minor PR"); | ||
| return {"issue": null}; | ||
| } | ||
|
|
||
| const match = title.match(/^GH-([0-9]+): .*$/); | ||
| if (match === null) { | ||
| core.setFailed("Invalid PR title format. Must either be MINOR: or GH-NNN:"); | ||
| return {"issue": null}; | ||
| } | ||
| return {"issue": parseInt(match[1], 10)}; | ||
| }, | ||
|
|
||
| apply_labels: async function({core, github, context}) { | ||
| const body = (context.payload.pull_request.body || "").split(/\n/g); | ||
| var has_breaking = false; | ||
| for (const line of body) { | ||
| if (line.trim().startsWith("**This contains breaking changes.**")) { | ||
| has_breaking = true; | ||
| break; | ||
| } | ||
| } | ||
| if (has_breaking) { | ||
| console.log("PR has breaking changes"); | ||
| await github.rest.issues.addLabels({ | ||
| issue_number: context.payload.pull_request.number, | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| labels: ["breaking-change"], | ||
| }); | ||
| } else { | ||
| console.log("PR has no breaking changes"); | ||
| } | ||
| }, | ||
|
|
||
| check_labels: async function({core, github, context}) { | ||
| const categories = ["bug-fix", "chore", "dependencies", "documentation", "enhancement"]; | ||
| const labels = (context.payload.pull_request.labels || []); | ||
| const required = new Set(categories); | ||
| var found = false; | ||
|
|
||
| for (const label of labels) { | ||
| console.log(`Found label ${label.name}`); | ||
| if (required.has(label.name)) { | ||
| found = true; | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| // Look to see if we left a comment before. | ||
| const comment_tag = "label_helper_comment"; | ||
| const maybe_comment_id = await have_comment(github, context, context.payload.pull_request.number, comment_tag); | ||
| console.log("Found comment?"); | ||
| console.log(maybe_comment_id); | ||
| const body_text = ` | ||
| <!-- ${comment_tag} --> | ||
| Thank you for opening a pull request! | ||
|
|
||
| Please label the PR with one or more of: | ||
|
|
||
| ${categories.map(c => `- ${c}`).join("\n")} | ||
|
|
||
| Also, add the 'breaking-change' label if appropriate. | ||
|
|
||
| See [CONTRIBUTING.md](https://github.com/apache/arrow-java/blob/main/CONTRIBUTING.md) for details. | ||
| `; | ||
|
|
||
| if (found) { | ||
| console.log("PR has appropriate label(s)"); | ||
| await upsert_comment(github, maybe_comment_id, body_text, false); | ||
| } else { | ||
| console.log(body_text); | ||
| await upsert_comment(github, maybe_comment_id, body_text, true); | ||
| core.setFailed("Missing required labels. See CONTRIBUTING.md"); | ||
| } | ||
| }, | ||
|
|
||
| check_linked_issue: async function({core, github, context, issue}) { | ||
| console.log(issue); | ||
| if (issue.issue === null) { | ||
| console.log("This is a MINOR PR"); | ||
| return; | ||
| } | ||
| const expected = `https://github.com/apache/arrow-java/issues/${issue.issue}`; | ||
|
|
||
| const query = ` | ||
| query($owner: String!, $name: String!, $number: Int!) { | ||
| repository(owner: $owner, name: $name) { | ||
| pullRequest(number: $number) { | ||
| closingIssuesReferences(first: 50) { | ||
| edges { | ||
| node { | ||
| number | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| }`; | ||
|
|
||
| const result = await github.graphql(query, { | ||
| owner: context.repo.owner, | ||
| name: context.repo.repo, | ||
| number: context.payload.pull_request.number, | ||
| }); | ||
| const issues = result.repository.pullRequest.closingIssuesReferences.edges; | ||
| console.log(issues); | ||
|
|
||
| for (const link of issues) { | ||
| console.log(`PR is linked to ${link.node.number}`); | ||
| if (link.node.number === issue.issue) { | ||
| console.log(`Found link to ${expected}`); | ||
| return; | ||
| } | ||
| } | ||
| console.log(`Did not find link to ${expected}`); | ||
| core.setFailed("Missing link to issue in title"); | ||
| }, | ||
| }; |
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,77 @@ | ||
| # 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 | ||
|
|
||
| on: | ||
| pull_request_target: | ||
| types: | ||
| - labeled | ||
| - unlabeled | ||
| - opened | ||
| - edited | ||
| - reopened | ||
| - synchronize | ||
| - ready_for_review | ||
| - review_requested | ||
|
|
||
| concurrency: | ||
| group: ${{ github.repository }}-${{ github.ref }}-${{ github.workflow }} | ||
| cancel-in-progress: true | ||
|
|
||
| permissions: | ||
| contents: read | ||
| pull-requests: write | ||
|
|
||
| jobs: | ||
| pr-label: | ||
| name: "Ensure PR format" | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4.0.0 | ||
| with: | ||
| fetch-depth: 0 | ||
| persist-credentials: false | ||
|
|
||
| - name: Ensure PR title format | ||
| id: title-format | ||
| uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 | ||
| with: | ||
| script: | | ||
| const scripts = require(`${process.env.GITHUB_WORKSPACE}/.github/workflows/dev_pr.js`); | ||
| return scripts.check_title_format({core, github, context}); | ||
|
|
||
| - name: Label PR | ||
| uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 | ||
| with: | ||
| script: | | ||
| const scripts = require(`${process.env.GITHUB_WORKSPACE}/.github/workflows/dev_pr.js`); | ||
| await scripts.apply_labels({core, github, context}); | ||
|
|
||
| - name: Ensure PR is labeled | ||
| uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 | ||
| with: | ||
| script: | | ||
| const scripts = require(`${process.env.GITHUB_WORKSPACE}/.github/workflows/dev_pr.js`); | ||
| await scripts.check_labels({core, github, context}); | ||
|
|
||
| - name: Ensure PR is linked to an issue | ||
| uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 | ||
| with: | ||
| script: | | ||
| const scripts = require(`${process.env.GITHUB_WORKSPACE}/.github/workflows/dev_pr.js`); | ||
| await scripts.check_linked_issue({core, github, context, issue: ${{ steps.title-format.outputs.result }}}); | ||
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.