You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by li...@apache.org on 2023/06/14 19:40:46 UTC

[arrow-adbc] branch main updated: ci: validate commit format more strictly (#791)

This is an automated email from the ASF dual-hosted git repository.

lidavidm pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-adbc.git


The following commit(s) were added to refs/heads/main by this push:
     new d3cf7141 ci: validate commit format more strictly (#791)
d3cf7141 is described below

commit d3cf7141000f0beb68ba5bb63d4d54cebd441783
Author: David Li <li...@gmail.com>
AuthorDate: Wed Jun 14 15:40:40 2023 -0400

    ci: validate commit format more strictly (#791)
    
    Fixes #425.
---
 .github/workflows/dev_pr.yml            |  2 +-
 .github/workflows/dev_pr/title_check.js | 32 +++++++++++++++++++++++++++++---
 2 files changed, 30 insertions(+), 4 deletions(-)

diff --git a/.github/workflows/dev_pr.yml b/.github/workflows/dev_pr.yml
index ad629df2..3d6cb852 100644
--- a/.github/workflows/dev_pr.yml
+++ b/.github/workflows/dev_pr.yml
@@ -47,4 +47,4 @@ jobs:
           github-token: ${{ secrets.GITHUB_TOKEN }}
           script: |
             const script = require(`${process.env.GITHUB_WORKSPACE}/.github/workflows/dev_pr/title_check.js`);
-            script({github, context});
+            await script({github, context});
diff --git a/.github/workflows/dev_pr/title_check.js b/.github/workflows/dev_pr/title_check.js
index 2f9f1c24..1c246e49 100644
--- a/.github/workflows/dev_pr/title_check.js
+++ b/.github/workflows/dev_pr/title_check.js
@@ -15,6 +15,8 @@
 // specific language governing permissions and limitations
 // under the License.
 
+const fs = require("fs");
+
 const COMMIT_TYPES = [
     'build',
     'chore',
@@ -32,12 +34,34 @@ const COMMIT_TYPES = [
 const COMMENT_BODY = ":warning: Please follow the [Conventional Commits format in CONTRIBUTING.md](https://github.com/apache/arrow-adbc/blob/main/CONTRIBUTING.md) for PR titles.";
 
 function matchesCommitFormat(title) {
-    const commitType = `(${COMMIT_TYPES.join('|')})`;
-    const scope = "(\\([a-zA-Z0-9_/\\-,]+\\))?";
+    const commitType = `(?:${COMMIT_TYPES.join('|')})`;
+    const scope = "(?:\\(([a-zA-Z0-9_/\\-,]+)\\))?";
     const delimiter = "!?:";
     const subject = " .+";
     const regexp = new RegExp(`^${commitType}${scope}${delimiter}${subject}$`);
-    return title.match(regexp) != null;
+
+    const matches = title.match(regexp);
+    if (matches === null) {
+        return false;
+    } else if (typeof matches[1] === "undefined") {
+        // No component
+        return true;
+    }
+
+    const components = matches[1].split(",");
+    console.info(`Components are ${components}`);
+    for (const component of components) {
+        if (component === "format") {
+            console.info(`Component is "format"`);
+            continue;
+        } else if (!fs.existsSync(component)) {
+            console.info(`Component "${component}" does not exist!`);
+            return false;
+        }
+        console.info(`Component "${component}" is valid`);
+    }
+
+    return true;
 }
 
 async function commentCommitFormat(github, context, pullRequestNumber) {
@@ -69,7 +93,9 @@ async function commentCommitFormat(github, context, pullRequestNumber) {
 module.exports = async ({github, context}) => {
     const pullRequestNumber = context.payload.number;
     const title = context.payload.pull_request.title;
+    console.info(`Checking title "${title}"`);
     if (!matchesCommitFormat(title)) {
+        console.info(`Title was not valid`);
         await commentCommitFormat(github, context, pullRequestNumber);
     }
 };