From add5d79f6e5b53e585b0e11ebd23d798e2eb5d3a Mon Sep 17 00:00:00 2001
From: David Li
Date: Fri, 7 Feb 2025 15:22:33 +0900
Subject: [PATCH 1/9] GH-499: Require PR labels for changelog
---
.github/workflows/dev_pr.yml | 72 ++++++++++++++++++++++++++++++++++++
CONTRIBUTING.md | 34 ++++++++++++++++-
2 files changed, 104 insertions(+), 2 deletions(-)
create mode 100644 .github/workflows/dev_pr.yml
diff --git a/.github/workflows/dev_pr.yml b/.github/workflows/dev_pr.yml
new file mode 100644
index 0000000000..3f96e17faf
--- /dev/null
+++ b/.github/workflows/dev_pr.yml
@@ -0,0 +1,72 @@
+# 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
+
+jobs:
+ pr-label:
+ name: "Ensure PR format"
+ runs-on: ubuntu-latest
+ steps:
+ - name: Ensure PR is labeled
+ env:
+ LABELS: ${{ toJson(github.event.pull_request.labels) }}
+ run: |
+ if ! echo "$LABELS" | jq -e '.[] | select(.name | IN("bug-fix", "dependencies", "enhancement")) | .name'; then
+ echo "Label the PR with one or more of:"
+ echo "- bug-fix"
+ echo "- dependencies"
+ echo "- enhancement"
+ echo
+ echo "Also, add 'breaking-change' if appropriate."
+ exit 1
+ else
+ echo "Pull request is labeled properly!"
+ fi
+
+ - name: Ensure PR title format
+ env:
+ TITLE: ${{ github.event.pull_request.title }}
+ run: |
+ set -x
+ if echo $TITLE | grep --extended-regexp "^MINOR: .*$" >/dev/null; then
+ echo "This is a MINOR PR."
+ elif echo $TITLE | grep --extended-regexp "^GH-[0-9]+: .*$" >/dev/null; then
+ echo "This is a normal PR."
+ else
+ echo "PR title format is incorrect. Please see CONTRIBUTING.md."
+ exit 1
+ fi
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 8388b1d6c7..a1c3e9a950 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -30,8 +30,38 @@ existing Arrow issues in [GitHub](https://github.com/apache/arrow-java/issues).
## Did you write a patch that fixes a bug or brings an improvement?
-Create a GitHub issue and submit your changes as a GitHub Pull Request.
-Please make sure to [reference the issue](https://docs.github.com/en/issues/tracking-your-work-with-issues/using-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword) in your PR description.
+- Create a GitHub issue and submit your changes as a GitHub Pull Request.
+- [Reference the issue](https://docs.github.com/en/issues/tracking-your-work-with-issues/using-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword) in your PR description.
+- Add one or more of the labels "bug-fix", "dependencies", and "enhancement" to your PR as appropriate.
+ - "bug-fix" is for PRs that fix a bug.
+ - "dependencies" is for PRs that upgrade a dependency or other administrative work (build system, release process, etc.).
+ - "enhancement" is for PRs that add new features.
+- Add the "breaking-change" label to your PR if there are breaking API changes.
+- Add the PR title. The PR title will be used as the eventual commit message, so please make it descriptive but succinct.
+
+Example #1:
+
+```
+GH-12345: Document the pull request process
+
+Explain how to open a pull request and what the title, body, and labels should be.
+
+Closes #12345.
+
+Labels: dependencies
+```
+
+Example #2:
+
+```
+GH-42424: Expose Netty server builder in Flight
+
+Allow direct usage of gRPC APIs for low-level control.
+
+Closes #42424.
+
+Labels: enhancement
+```
### Minor Fixes
From a6b8e14010bea89c633966edcc1452b3bd312a3e Mon Sep 17 00:00:00 2001
From: David Li
Date: Mon, 10 Feb 2025 14:25:53 +0900
Subject: [PATCH 2/9] better automation
---
.github/pull_request_template.md | 8 ++
.github/workflows/dev_pr.js | 126 +++++++++++++++++++++++++++++++
.github/workflows/dev_pr.yml | 58 +++++++-------
CONTRIBUTING.md | 6 +-
4 files changed, 169 insertions(+), 29 deletions(-)
create mode 100644 .github/pull_request_template.md
create mode 100644 .github/workflows/dev_pr.js
diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md
new file mode 100644
index 0000000000..ccaaadfd02
--- /dev/null
+++ b/.github/pull_request_template.md
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
-
-
+## What's Changed
-
-
+Please fill in a description of the changes here.
-
+
+Closes #NNN.
From a6f52d92e4cbc3d6f1bfbf34aeb59c84962f107c Mon Sep 17 00:00:00 2001
From: David Li
Date: Mon, 10 Feb 2025 21:21:05 +0900
Subject: [PATCH 5/9] issue comment
---
.github/workflows/dev_pr.js | 127 ++++++++++++++++++++++++++++++++---
.github/workflows/dev_pr.yml | 1 +
2 files changed, 120 insertions(+), 8 deletions(-)
diff --git a/.github/workflows/dev_pr.js b/.github/workflows/dev_pr.js
index 85f4985b95..b572ce629e 100644
--- a/.github/workflows/dev_pr.js
+++ b/.github/workflows/dev_pr.js
@@ -15,6 +15,104 @@
// specific language governing permissions and limitations
// under the License.
+async function have_comment(github, context, pr_number, tag) {
+ const query = `
+query($owner: String!, $name: String!, $number: Int!, $cursor: String) {
+ repository(owner: $owner, name: $name) {
+ pullRequest(number: $number) {
+ comments (after:$cursor, first: 50) {
+ nodes {
+ id
+ bodyText
+ 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,
+ });
+ console.log(result);
+ pr_id = result.repository.pullRequest.id;
+ cursor = result.repository.pullRequest.comments.pageInfo;
+ const comments = result.repository.pullRequest.comments.nodes;
+
+ for (const comment of comments) {
+ if (comment.author.login === "github-actions[bot]" &&
+ comment.bodyText.match(tag_regexp) !== null) {
+ return {pr_id, comment_id: comment.id};
+ }
+ }
+
+ if (!result.repository.pullRequest.comments.hasNextPage ||
+ comments.length === 0) {
+ break;
+ }
+ }
+ 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;
@@ -67,17 +165,30 @@ module.exports = {
}
}
+ // 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 = `
+
+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("PR has is missing label(s)");
- console.log("Label the PR with one or more of:");
- for (const label of categories) {
- console.log(`- ${label}`);
- }
- console.log();
- console.log("Also, add 'breaking-change' if appropriate.");
- console.log("See CONTRIBUTING.md for details.");
+ console.log(body_text);
+ await upsert_comment(github, maybe_comment_id, body_text, true);
core.setFailed("Missing required labels. See CONTRIBUTING.md");
}
},
diff --git a/.github/workflows/dev_pr.yml b/.github/workflows/dev_pr.yml
index d680fa2d5f..719cd1feb6 100644
--- a/.github/workflows/dev_pr.yml
+++ b/.github/workflows/dev_pr.yml
@@ -35,6 +35,7 @@ concurrency:
permissions:
contents: read
+ pull-requests: write
jobs:
pr-label:
From df4cd4b73dcf972d8f2383ab9cea08455cbe3397 Mon Sep 17 00:00:00 2001
From: David Li
Date: Wed, 12 Feb 2025 23:09:29 -0500
Subject: [PATCH 6/9] fix comment
---
.github/workflows/dev_pr.js | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/.github/workflows/dev_pr.js b/.github/workflows/dev_pr.js
index b572ce629e..19fd6e5695 100644
--- a/.github/workflows/dev_pr.js
+++ b/.github/workflows/dev_pr.js
@@ -16,14 +16,16 @@
// 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
- bodyText
+ body
author {
login
}
@@ -47,14 +49,15 @@ query($owner: String!, $name: String!, $number: Int!, $cursor: String) {
number: pr_number,
cursor,
});
- console.log(result);
pr_id = result.repository.pullRequest.id;
cursor = result.repository.pullRequest.comments.pageInfo;
const comments = result.repository.pullRequest.comments.nodes;
for (const comment of comments) {
- if (comment.author.login === "github-actions[bot]" &&
- comment.bodyText.match(tag_regexp) !== null) {
+ 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};
}
}
@@ -64,6 +67,7 @@ query($owner: String!, $name: String!, $number: Int!, $cursor: String) {
break;
}
}
+ console.log("No existing comment");
return {pr_id, comment_id: null};
}
From d4075c1dff3ea9e1d6859a61d1318309df686f50 Mon Sep 17 00:00:00 2001
From: David Li
Date: Thu, 13 Feb 2025 00:58:28 -0500
Subject: [PATCH 7/9] Update .github/workflows/dev_pr.yml
Co-authored-by: Sutou Kouhei
---
.github/workflows/dev_pr.yml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/.github/workflows/dev_pr.yml b/.github/workflows/dev_pr.yml
index 719cd1feb6..8da3ab5fd5 100644
--- a/.github/workflows/dev_pr.yml
+++ b/.github/workflows/dev_pr.yml
@@ -42,7 +42,7 @@ jobs:
name: "Ensure PR format"
runs-on: ubuntu-latest
steps:
- - uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4.0.0
+ - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
fetch-depth: 0
persist-credentials: false
From ac75e64352994d93057d51621b4854739ef7f504 Mon Sep 17 00:00:00 2001
From: David Li
Date: Thu, 13 Feb 2025 00:58:41 -0500
Subject: [PATCH 8/9] Update CONTRIBUTING.md
Co-authored-by: Sutou Kouhei
---
CONTRIBUTING.md | 2 --
1 file changed, 2 deletions(-)
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 5a5a8bb466..6c25c47196 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -49,8 +49,6 @@ GH-12345: Document the pull request process
Explain how to open a pull request and what the title, body, and labels should be.
Closes #12345.
-
-Labels: dependencies
```
Example #2:
From e46f293d5078fe8cba4ccc3c1c6ed967dfd5e0f2 Mon Sep 17 00:00:00 2001
From: David Li
Date: Thu, 13 Feb 2025 00:58:47 -0500
Subject: [PATCH 9/9] Update CONTRIBUTING.md
Co-authored-by: Sutou Kouhei
---
CONTRIBUTING.md | 2 --
1 file changed, 2 deletions(-)
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 6c25c47196..680750070f 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -59,8 +59,6 @@ GH-42424: Expose Netty server builder in Flight
Allow direct usage of gRPC APIs for low-level control.
Closes #42424.
-
-Labels: enhancement
```
### Minor Fixes