Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 24 Jan 2025 20:50:51 +0000
From:      Jessica Clarke <jrtc27@freebsd.org>
To:        Ed Maste <emaste@FreeBSD.org>
Cc:        "src-committers@freebsd.org" <src-committers@FreeBSD.org>, "dev-commits-src-all@freebsd.org" <dev-commits-src-all@FreeBSD.org>, "dev-commits-src-main@freebsd.org" <dev-commits-src-main@FreeBSD.org>
Subject:   Re: git: a9a6a51edac1 - main - github: Add new checklist workflow
Message-ID:  <A3654460-A2CB-4317-AB4E-9CF827F4301F@freebsd.org>
In-Reply-To: <202501242027.50OKRiIe064626@gitrepo.freebsd.org>
References:  <202501242027.50OKRiIe064626@gitrepo.freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On 24 Jan 2025, at 20:27, Ed Maste <emaste@FreeBSD.org> wrote:
>=20
> The branch main has been updated by emaste:
>=20
> URL: =
https://cgit.FreeBSD.org/src/commit/?id=3Da9a6a51edac13aaff5517dd602272152=
efa6d7bd
>=20
> commit a9a6a51edac13aaff5517dd602272152efa6d7bd
> Author:     Ahmad Khalifa <ahmadkhalifa570@gmail.com>
> AuthorDate: 2025-01-05 05:01:07 +0000
> Commit:     Ed Maste <emaste@FreeBSD.org>
> CommitDate: 2025-01-24 20:27:08 +0000
>=20
>    github: Add new checklist workflow
>=20
>    Add a new 'checklist' workflow that checks the commit messages on =
pull
>    requests. Currently, the workflow creates a comment on the pull =
request
>    if any of these conditions are hit:
>      - Missing Signed-off-by
>      - Malformed Signed-off-by
>      - Bad email (i.e *noreply*)
>=20
>    Reviewed by:    emaste, imp
>    Pull request:   https://github.com/freebsd/freebsd-src/pull/1570
>=20
>    Signed-off-by: Ahmad Khalifa <ahmadkhalifa570@gmail.com>
> ---
> .github/workflows/checklist.yml | 106 =
++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 106 insertions(+)
>=20
> diff --git a/.github/workflows/checklist.yml =
b/.github/workflows/checklist.yml
> new file mode 100644
> index 000000000000..9734af4a1a1d
> --- /dev/null
> +++ b/.github/workflows/checklist.yml
> @@ -0,0 +1,106 @@
> +name: Checklist
> +
> +# Produce a list of things that need to be changed
> +# for the submission to align with CONTRIBUTING.md
> +
> +on:
> +  pull_request:
> +    types: [ opened, reopened, edited, synchronize ]
> +
> +permissions:
> +  pull-requests: write
> +
> +jobs:
> +  checklist:
> +    name: commit
> +    runs-on: ubuntu-latest

Please be careful to restrict these kinds of jobs with

  if: github.repository_owner =3D=3D 'freebsd'

or

  if: github.repository =3D=3D 'freebsd/freebsd-src'

otherwise it=E2=80=99s a pain for forks.

Jess

> +    steps:
> +      - uses: actions/github-script@v7
> +        with:
> +          # An asynchronous javascript function
> +          script: |
> +            /*
> +             * Github's API returns the results in pages of 30, so
> +             * pass the function we want, along with it's arguments,
> +             * to paginate() which will handle gathering all the =
results.
> +             */
> +            const comments =3D await =
github.paginate(github.rest.issues.listComments, {
> +              owner: context.repo.owner,
> +              repo: context.repo.repo,
> +              issue_number: context.issue.number
> +            });
> +
> +            const commits =3D await =
github.paginate(github.rest.pulls.listCommits, {
> +              owner: context.repo.owner,
> +              repo: context.repo.repo,
> +              pull_number: context.issue.number
> +            });
> +
> +            let checklist =3D {};
> +            let checklist_len =3D 0;
> +            let comment_id =3D -1;
> +
> +            const msg_prefix =3D "Thank you for taking the time to =
contribute to FreeBSD!\n";
> +            const addToChecklist =3D (msg, sha) =3D> {
> +              if (!checklist[msg]) {
> +                checklist[msg] =3D [];
> +                checklist_len++;
> +              }
> +              checklist[msg].push(sha);
> +            }
> +
> +            for (const commit of commits) {
> +              const sob_lines =3D =
commit.commit.message.match(/^[^\S\r\n]*signed-off-by:.*/gim);
> +
> +              if (sob_lines =3D=3D null && =
!commit.commit.author.email.toLowerCase().endsWith("freebsd.org"))
> +                addToChecklist("Missing Signed-off-by lines", =
commit.sha);
> +              else if (sob_lines !=3D null) {
> +                let author_signed =3D false;
> +                for (const line of sob_lines) {
> +                  if (!line.includes("Signed-off-by: "))
> +                    /* Only display the part we care about. */
> +                    addToChecklist("Expected `Signed-off-by: `, got =
`" + line.match(/^[^\S\r\n]*signed-off-by:./i) + "`", commit.sha);
> +                  if (line.includes(commit.commit.author.email))
> +                    author_signed =3D true;
> +                }
> +
> +                if (!author_signed)
> +                  console.log("::warning =
title=3DMissing-Author-Signature::Missing Signed-off-by from author");
> +              }
> +
> +              if =
(commit.commit.author.email.toLowerCase().includes("noreply"))
> +                addToChecklist("Real email address is needed", =
commit.sha);
> +            }
> +
> +            /* Check if we've commented before. */
> +            for (const comment of comments) {
> +              if (comment.user.login =3D=3D "github-actions[bot]") {
> +                comment_id =3D comment.id;
> +                break;
> +              }
> +            }
> +
> +            if (checklist_len !=3D 0) {
> +              let msg =3D msg_prefix +
> +                "There " + (checklist_len > 1 ? "are a few issues =
that need " : "is an issue that needs ") +
> +                "to be fixed:\n";
> +              let comment_func =3D comment_id =3D=3D -1 ? =
github.rest.issues.createComment : github.rest.issues.updateComment;
> +
> +              /* Loop for each key in "checklist". */
> +              for (const c in checklist)
> +                msg +=3D "- " + c + "<sup>" + checklist[c].join(", ") =
+ "</sup>\n";
> +
> +              comment_func({
> +                owner: context.repo.owner,
> +                repo: context.repo.repo,
> +                body: msg,
> +                ...(comment_id =3D=3D -1 ? {issue_number: =
context.issue.number} : {comment_id: comment_id})
> +              });
> +            } else if (comment_id !=3D -1) {
> +              github.rest.issues.updateComment({
> +                owner: context.repo.owner,
> +                repo: context.repo.repo,
> +                comment_id: comment_id,
> +                body: msg_prefix + "All issues resolved."
> +              });
> +            }




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?A3654460-A2CB-4317-AB4E-9CF827F4301F>