Skip to content
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

ci: verify changes to Maintainers.yaml made by the bot #750

Merged
merged 45 commits into from
Aug 9, 2023
Merged
Changes from 32 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
2062642
added new workflow to validate maintainers
14Richa Jun 15, 2023
514aa22
added msg body when PR is raised by human
14Richa Jun 16, 2023
f77acfc
changed maintainers.yaml caps also declared new var PATH
14Richa Jun 20, 2023
7688bdd
changed file name and workflow file name
14Richa Jun 27, 2023
4fc28ad
Merge branch 'master' into 14Richa/validate-maintainers
14Richa Jun 27, 2023
65bea9f
added script
14Richa Jun 28, 2023
0b074bb
added close pr and comment on pr functionality
14Richa Jun 28, 2023
c224cb1
minor fix in maintainers file name
14Richa Jun 28, 2023
cb4acd2
updated the version
14Richa Jun 28, 2023
7f21761
updated the verify maintainer workflw
14Richa Jun 29, 2023
61ffea8
deleted the script
14Richa Jun 29, 2023
e1dbd58
minor fix related to file name
14Richa Jun 30, 2023
5ebc520
minor fix added errormessage array
14Richa Jul 3, 2023
3e3de3f
Merge branch 'master' into 14Richa/validate-maintainers
14Richa Jul 4, 2023
1d181b6
Update .github/workflows/verify-maintainers.yaml
14Richa Jul 4, 2023
514489e
Update .github/workflows/verify-maintainers.yaml
14Richa Jul 4, 2023
0df6a07
Update .github/workflows/verify-maintainers.yaml
14Richa Jul 4, 2023
9c788f7
Update .github/workflows/verify-maintainers.yaml
14Richa Jul 4, 2023
a1cdb43
fixed error messages
14Richa Jul 4, 2023
682ac24
added comment
14Richa Jul 4, 2023
8dfe2fb
removed a function createComment
14Richa Jul 4, 2023
5f63633
used toString method
14Richa Jul 4, 2023
20cef78
added comments in the script
14Richa Jul 4, 2023
cc5fc18
minor fix
14Richa Jul 5, 2023
1608a1f
Update .github/workflows/verify-maintainers.yaml
14Richa Jul 5, 2023
9835e3d
added conditon on pr open
14Richa Jul 5, 2023
5da2a91
added a new check to repo list added
14Richa Jul 10, 2023
b496dd5
Update .github/workflows/verify-maintainers.yaml
14Richa Jul 11, 2023
0ff69b1
Update .github/workflows/verify-maintainers.yaml
14Richa Jul 11, 2023
39bdae7
Update .github/workflows/verify-maintainers.yaml
14Richa Jul 11, 2023
4fd66a2
Update .github/workflows/verify-maintainers.yaml
14Richa Jul 11, 2023
8dcd297
Update .github/workflows/verify-maintainers.yaml
14Richa Jul 11, 2023
d0e5fc9
Update .github/workflows/verify-maintainers.yaml
14Richa Jul 11, 2023
6e936d7
added remove code in repo condition
14Richa Jul 11, 2023
7b9104a
Merge branch '14Richa/validate-maintainers' of github.com:14Richa/com…
14Richa Jul 11, 2023
4f52673
Update .github/workflows/verify-maintainers.yaml
14Richa Jul 12, 2023
a4ea5db
minor fix in msg
14Richa Jul 13, 2023
601e49c
Merge branch '14Richa/validate-maintainers' of github.com:14Richa/com…
14Richa Jul 13, 2023
6ae39fe
Merge branch 'master' into 14Richa/validate-maintainers
derberg Jul 31, 2023
63b19b0
made changes in verify maintainer changes
14Richa Aug 1, 2023
d816f22
Merge branch '14Richa/validate-maintainers' of github.com:14Richa/com…
14Richa Aug 1, 2023
b9cf2b1
syntax fix
14Richa Aug 3, 2023
24de526
update the workflow divided the workflow in jobs
14Richa Aug 3, 2023
9d2a42c
update the token name
14Richa Aug 3, 2023
3e03b9a
Merge branch 'master' into 14Richa/validate-maintainers
derberg Aug 8, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 98 additions & 0 deletions .github/workflows/verify-maintainers.yaml
14Richa marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
name: Verify if human changes in PR are allowed

on:
pull_request:
types: [synchronize, opened]
14Richa marked this conversation as resolved.
Show resolved Hide resolved
paths:
- "MAINTAINERS.yaml"

jobs:
verify-changes:
14Richa marked this conversation as resolved.
Show resolved Hide resolved
# if statement to check if the PR is open.
if: github.event.pull_request.state == 'open'
runs-on: ubuntu-latest
steps:
- name: Checkout main branch
uses: actions/checkout@v3
with:
ref: master
path: community-main

- name: Checkout PR branch
uses: actions/checkout@v3
with:
ref: ${{ github.head_ref }}
path: pr-branch

- name: Install Dependencies
run: npm install yaml

- name: Verify changes in MAINTAINERS.yaml
id: verify-changes
uses: actions/github-script@v5
14Richa marked this conversation as resolved.
Show resolved Hide resolved
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const yaml = require("yaml");
const fs = require("fs");

const mainFile = yaml.parse(fs.readFileSync("./community-main/MAINTAINERS.yaml", "utf8"));
const prFile = yaml.parse(fs.readFileSync("./pr-branch/MAINTAINERS.yaml", "utf8"));

const beforeMaintainers = new Map(mainFile.map((maintainer) => [maintainer.name, {github: maintainer.github, repos: maintainer.repos || []}]));
let errorMessages = [];

const owner = context.repo.owner;
const repo = context.repo.repo;
const pull_number = context.issue.number;
const author = context.payload.pull_request.user.login;

// If the PR is made by the bot, don't do anything.
if (author === 'asyncapi-bot') {
console.log('Changes made by asyncapi-bot, skipping verification.');
return;
}

// detecting if changes in the PR contain removal of maintainer object
if (prFile.length < mainFile.length) {
errorMessages.push('A maintainer has been removed from `MAINTAINERS.yaml` file. Only `asyncapi-bot` can make such changes. Maintainers are removed from the file in an automated way only if they are no longer mentioned in `CODEOWNERS` file in any repository under AsyncAPI GitHub organization.');
}

for (const maintainer of prFile) {
// retrieve the previous data of the maintainer from the main file
const previousData = beforeMaintainers.get(maintainer.name);
// if the maintainer is not found in the previous data, it is a new maintainer
if (!previousData) {
14Richa marked this conversation as resolved.
Show resolved Hide resolved
errorMessages.push(`A new maintainer, ${maintainer.name}, has been added to MAINTAINERS.yaml. Only asyncapi-bot can make such changes. Maintainers are added to the file in an automated way only if they are mentioned in the CODEOWNERS file in any repository under AsyncAPI GitHub organization.`);
} else {
14Richa marked this conversation as resolved.
Show resolved Hide resolved
// retrieve the previous GitHub key and repositories of the maintainer
const previousGithub = previousData.github;
const previousRepos = previousData.repos;
// check if the GitHub key for the maintainer has been modified
if (previousGithub !== maintainer.github) {
14Richa marked this conversation as resolved.
Show resolved Hide resolved
errorMessages.push(`GitHub key for ${maintainer.name} has been modified in MAINTAINERS.yaml. Only asyncapi-bot can make such changes. This information is derived from the CODEOWNERS file located in any repository under AsyncAPI GitHub organization.`);
}
// check if the repositories list for the maintainer has been modified
if (previousRepos.toString() !== (maintainer.repos || []).toString()) {
// Check if a human added a repo to the maintainer's repository list
const previousReposLength = previousData.repos.length;
const currentReposLength = (maintainer.repos || []).length;
if (currentReposLength > previousReposLength) {
const addedRepos = (maintainer.repos || []).slice(previousReposLength);
errorMessages.push(`New repositories (${addedRepos.join(', ')}) have been added to ${maintainer.name}'s repository list in MAINTAINERS.yaml. Only asyncapi-bot can make such changes. This information is derived from the CODEOWNERS file located in any repository under AsyncAPI GitHub organization.`);
}
}
}
}

// If there are any error messages, create a comment on the PR and close it
if (errorMessages.length > 0) {
const commentBody = errorMessages.join('\n');
github.rest.issues.createComment({ owner, repo, issue_number: pull_number, body: commentBody });
github.rest.pulls.update({
owner,
repo,
pull_number,
state: 'closed'
});
}