2023-02-27 13:39:09 +01:00
name : Pending reviews automation
on :
2024-09-17 12:07:40 +02:00
# The bot exceeded its API rate limit. Disabling for now (adding workflow dispatch so the workflow file stays valid & we can test to see if it starts working again)
workflow_dispatch : {}
2023-02-27 13:39:09 +01:00
# We run it on a schedule instead of on pull_request_* events to not create confusing messaging in the PR
2024-09-17 12:07:40 +02:00
#schedule:
# - cron: "*/10 * * * *"
2023-02-27 13:39:09 +01:00
concurrency : ${{ github.workflow }}
2024-11-20 16:44:02 +01:00
permissions : {} # We use ELEMENT_BOT_TOKEN instead
2023-02-27 13:39:09 +01:00
jobs :
bot :
name : Pending reviews bot
2024-10-17 12:10:32 +02:00
runs-on : ubuntu-24.04
2023-02-27 13:39:09 +01:00
environment : Matrix
env :
2023-12-12 11:31:44 +01:00
URL : "https://github.com/pulls?q=is%3Apr+is%3Aopen+repo%3Amatrix-org%2Fmatrix-js-sdk+repo%3Amatrix-org%2Fmatrix-react-sdk+repo%3Aelement-hq%2Felement-web+repo%3Aelement-hq%2Felement-desktop+review-requested%3A%40me+sort%3Aupdated-desc+"
RELEASE_BLOCKERS_URL : "https://github.com/pulls?q=is%3Aopen+repo%3Amatrix-org%2Fmatrix-js-sdk+repo%3Amatrix-org%2Fmatrix-react-sdk+repo%3Aelement-hq%2Felement-web+repo%3Aelement-hq%2Felement-desktop+sort%3Aupdated-desc+label%3AX-Release-Blocker+"
2023-02-27 13:39:09 +01:00
steps :
2023-11-15 23:29:06 +01:00
- uses : actions/github-script@v7
2023-02-27 13:39:09 +01:00
env :
HS_URL : ${{ secrets.BETABOT_HS_URL }}
ROOM_ID : ${{ secrets.ROOM_ID }}
TOKEN : ${{ secrets.BETABOT_ACCESS_TOKEN }}
with :
# PAT needed as the GITHUB_TOKEN won't be able to see cross-references from other orgs (matrix-org)
github-token : ${{ secrets.ELEMENT_BOT_TOKEN }}
script : |
2023-05-30 11:56:19 +02:00
const { HS_URL, ROOM_ID, TOKEN, URL, RELEASE_BLOCKERS_URL } = process.env;
async function updateCounter(counter, link, severity, title, value, clearOnZero) {
const apiUrl = `${HS_URL}/_matrix/client/v3/rooms/${ROOM_ID}/state/re.jki.counter/${counter}`;
const headers = {
"Content-Type": "application/json" ,
"Authorization": `Bearer ${TOKEN}`,
};
const res = await fetch(apiUrl, {
method : "GET" ,
headers,
});
const data = await res.json();
if (data.value === issueCount) {
console.log("Pending review count already correct");
return;
}
let body = {};
if (issueCount || !clearOnZero) {
body = JSON.stringify({
link,
severity,
title,
value,
});
}
await fetch(apiUrl, {
method : "PUT" ,
body,
headers,
});
}
2023-02-27 13:39:09 +01:00
const repos = [
2023-12-12 11:31:44 +01:00
"element-hq/element-desktop" ,
"element-hq/element-web" ,
2023-02-27 13:39:09 +01:00
"matrix-org/matrix-js-sdk" ,
] ;
const teams = [
2024-01-03 11:57:51 +01:00
"matrix-org/element-web-team" ,
"matrix-org/element-web-reviewers" ,
"element-hq/element-web-team" ,
"element-hq/element-web-reviewers" ,
2023-02-27 13:39:09 +01:00
] ;
let issueCount = 0;
for (const team of teams) {
const org = team.split("/", 2)[0];
const reposInOrg = repos.filter(repo => repo.startsWith(org + "/"));
const { data } = await github.rest.search.issuesAndPullRequests({
q : `is:pr is:open review:required ${reposInOrg.map(r => `repo:${r}`).join(" ")} team-review-requested:${team}`,
});
issueCount += data.total_count;
}
2023-05-30 11:56:19 +02:00
await updateCounter("gh_reviews", URL, "warning", "Pending reviews", issueCount);
2023-02-27 13:39:09 +01:00
2023-05-30 11:56:19 +02:00
const { data } = await github.rest.search.issuesAndPullRequests({
2023-05-30 12:59:33 +02:00
q : `is:open ${repos.map(repo => `repo:${repo}`).join(" ")} label:X-Release-Blocker`,
2023-02-27 13:39:09 +01:00
});
2023-05-30 11:56:19 +02:00
const blockerCount = data.total_count;
2023-05-30 13:22:17 +02:00
await updateCounter("release_blockers", RELEASE_BLOCKERS_URL, "alert", "Release Blockers", blockerCount, true);