Skip to content

Commit

Permalink
Remove the "2 Reviews Needed" column automation from the PR board (#4657
Browse files Browse the repository at this point in the history
)

Co-authored-by: Dhruv Bhanushali <[email protected]>
  • Loading branch information
zackkrida and dhruvkb authored Jul 25, 2024
1 parent b96fc34 commit c68dcd6
Show file tree
Hide file tree
Showing 12 changed files with 133 additions and 142 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ repos:

- id: eslint
name: eslint
files: (frontend|automations|packages/js).*?\.(js|ts|vue|json5|json)$
files: (frontend|automations|packages/js).*?\.(js|ts|mjs|vue|json5|json)$
"types": [file] # ESLint only accepts [javascript] by default.
language: system
pass_filenames: false
Expand Down
6 changes: 0 additions & 6 deletions automations/js/prettier.config.js

This file was deleted.

14 changes: 7 additions & 7 deletions automations/js/src/count_user_reviewable_prs.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module.exports = async ({ github, context, core }) => {
const slackID = JSON.parse(GH_SLACK_USERNAME_MAP)[context.actor]

if (!GITHUB_REPOSITORY || !GH_SLACK_USERNAME_MAP) {
core.setFailed('Required dependencies were not supplied')
core.setFailed("Required dependencies were not supplied")
}

if (!slackID) {
Expand Down Expand Up @@ -44,11 +44,11 @@ query ($repoOwner: String!, $repo: String!, $cursor: String) {
}
`
const ignoredLabels = [
'🤖 aspect: text',
'🧱 stack: documentation',
'🟥 priority: critical',
"🤖 aspect: text",
"🧱 stack: documentation",
"🟥 priority: critical",
]
const [owner, repo] = GITHUB_REPOSITORY.split('/')
const [owner, repo] = GITHUB_REPOSITORY.split("/")
const isRelevantPrFromGraphql = (pr) =>
pr.author.login === context.actor &&
!pr.isDraft &&
Expand Down Expand Up @@ -90,8 +90,8 @@ query ($repoOwner: String!, $repo: String!, $cursor: String) {
}

core.info(`Current user has ${result.pr_count} PR(s).`)
core.setOutput('pr_count', result.pr_count)
core.setOutput('slack_id', result.slack_id)
core.setOutput("pr_count", result.pr_count)
core.setOutput("slack_id", result.slack_id)
} catch (error) {
core.setFailed(`Error fetching pull requests: ${error.message}`)
}
Expand Down
40 changes: 20 additions & 20 deletions automations/js/src/label_pr.mjs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { readFileSync } from 'fs'
import { PullRequest } from './utils/pr.mjs'
import { IdSet } from './utils/id_set.mjs'
import { readFileSync } from "fs"
import { PullRequest } from "./utils/pr.mjs"
import { IdSet } from "./utils/id_set.mjs"

const exactlyOne = ['priority', 'goal']
const atleastOne = ['aspect', 'stack']
const exactlyOne = ["priority", "goal"]
const atleastOne = ["aspect", "stack"]

const pathLabels = {
migrations: 'migrations',
project_proposal: '🧭 project: proposal',
project_ip: '🧭 project: implementation plan',
migrations: "migrations",
project_proposal: "🧭 project: proposal",
project_ip: "🧭 project: implementation plan",
}

/**
Expand All @@ -20,9 +20,9 @@ const pathLabels = {
*/
function getLabelsFromChanges(allLabels, changes) {
const applicableLabels = allLabels
.filter((label) => label.name.startsWith('🧱 stack:'))
.filter((label) => label.name.startsWith("🧱 stack:"))
.filter((label) => {
const [, stackName] = label.name.split(': ')
const [, stackName] = label.name.split(": ")
return changes.includes(stackName)
})
Object.entries(pathLabels).forEach(([group, labelName]) => {
Expand Down Expand Up @@ -61,7 +61,7 @@ function getIsFullyLabeled(labels) {
* @returns {import('./utils/pr.mjs').Label[]} the label with the `id` and `name` fields
*/
async function getAllLabels(octokit, repository) {
const [owner, repo] = repository.split('/')
const [owner, repo] = repository.split("/")
const res = await octokit.rest.issues.listLabelsForRepo({
owner,
repo,
Expand All @@ -82,15 +82,15 @@ async function getAllLabels(octokit, repository) {
export const main = async (octokit, core) => {
const { GITHUB_REPOSITORY } = process.env
const { eventName, eventAction, prNodeId } = JSON.parse(
readFileSync('/tmp/event.json', 'utf-8')
readFileSync("/tmp/event.json", "utf-8")
)
const changes = JSON.parse(readFileSync('/tmp/change.json', 'utf-8'))
const changes = JSON.parse(readFileSync("/tmp/change.json", "utf-8"))

const allLabels = await getAllLabels(octokit, GITHUB_REPOSITORY)

if (
eventName !== 'pull_request' ||
!['opened', 'edited'].includes(eventAction)
eventName !== "pull_request" ||
!["opened", "edited"].includes(eventAction)
) {
core.info(
`Event "${eventName}"/"${eventAction}" is not an event where a PR should be labelled.`
Expand All @@ -104,7 +104,7 @@ export const main = async (octokit, core) => {
let isTriaged = false
if (pr.labels.length) {
// If a PR already has some labels, it is considered triaged.
core.info('The PR already has some labels.')
core.info("The PR already has some labels.")
isTriaged = true
}

Expand All @@ -128,7 +128,7 @@ export const main = async (octokit, core) => {
// Then we compile all the labels of all the linked issues into a pool. This
// will be used to find the labels that satisfy the requirements.
const labelPool = pr.linkedIssues.flatMap((issue) => issue.labels)
core.debug(`Label pool: ${labelPool.map((label) => label.name).join(',')}`)
core.debug(`Label pool: ${labelPool.map((label) => label.name).join(",")}`)

// For each label that we only need one of, we check if the PR already has
// such a label. If not, we check if the label pool contains any valid labels
Expand All @@ -152,7 +152,7 @@ export const main = async (octokit, core) => {
core.info(
`Adding labels "${validLabels
.map((label) => label.name)
.join(',')}" to PR.`
.join(",")}" to PR.`
)
validLabels.forEach((label) => {
finalLabels.add(label)
Expand All @@ -164,9 +164,9 @@ export const main = async (octokit, core) => {
if (!getIsFullyLabeled(finalLabels.items)) {
let attnLabel
if (isTriaged) {
attnLabel = '🏷 status: label work required'
attnLabel = "🏷 status: label work required"
} else {
attnLabel = '🚦 status: awaiting triage'
attnLabel = "🚦 status: awaiting triage"
}
core.info(`PR not fully labelled so adding "${attnLabel}".`)
attnLabel = allLabels.filter((item) => item.name === attnLabel)[0]
Expand Down
46 changes: 23 additions & 23 deletions automations/js/src/last_week_tonight.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
* Openverse repos.
*/

import { readFileSync } from 'fs'
import { resolve } from 'path'
import { readFileSync } from "fs"
import { resolve } from "path"

import yaml from 'js-yaml'
import axios from 'axios'
import { Octokit } from '@octokit/rest'
import yaml from "js-yaml"
import axios from "axios"
import { Octokit } from "@octokit/rest"

import { escapeHtml } from './utils/html.mjs'
import { escapeHtml } from "./utils/html.mjs"

/* Environment variables */

Expand All @@ -34,7 +34,7 @@ if (!(pat && username && password)) process.exit(1)

/* Read GitHub information from the data files */

const githubDataFile = resolve('../data/github.yml') // resolved from `package.json`
const githubDataFile = resolve("../data/github.yml") // resolved from `package.json`
const githubInfo = yaml.load(readFileSync(githubDataFile))
const org = githubInfo.org
const repos = Object.values(githubInfo.repos)
Expand All @@ -43,11 +43,11 @@ const repos = Object.values(githubInfo.repos)

const msInWeeks = (weeks) => weeks * 7 * 24 * 60 * 60 * 1e3
// End date is always today
const [endDate] = new Date().toISOString().split('T')
const [endDate] = new Date().toISOString().split("T")
// Start date is one week before today
const [startDate] = new Date(new Date().getTime() - msInWeeks(1))
.toISOString()
.split('T')
.split("T")

/* GitHub API */

Expand All @@ -60,8 +60,8 @@ const closedIssuesQ = (repo) =>
/* Other constants */

const stackNameMap = {
api: 'API',
mgmt: 'Management',
api: "API",
mgmt: "Management",
}

/* Format issues, PRs and repos as HTML */
Expand All @@ -82,15 +82,15 @@ const getItemsHtml = (title, items) => {
items
.flatMap((item) => item.labels) // Flatten all labels into a single array
.map((label) => label.name) // Extract the name of each label
.filter((name) => name.startsWith('🧱 stack'))
.filter((name) => name.startsWith("🧱 stack"))
),
].sort()

// Aggregate items by stack
let itemsByStack = {}

for (const stack of stacks) {
const stackName = stack.split(':')[1].trim()
const stackName = stack.split(":")[1].trim()
itemsByStack[stackName] = items
.filter((item) => item.labels.map((label) => label.name).includes(stack))
.sort((a, b) => a.number - b.number)
Expand All @@ -102,14 +102,14 @@ const getItemsHtml = (title, items) => {
...Object.entries(itemsByStack)
.map(([stackName, items]) => [
`<h4>${stackNameMap[stackName] || stackName.replace(/\b[a-z]/g, (match) => match.toUpperCase())}</h4>`,
'<ul>',
"<ul>",
...items.map((item) => {
const href = item.html_url
const number = `#${item.number}`
const title = escapeHtml(item.title)
return `<li><a href="${href}">${number}</a>: ${title}`
}),
'</ul>',
"</ul>",
])
.flat(),
]
Expand All @@ -126,8 +126,8 @@ const getItemsHtml = (title, items) => {
const getRepoHtml = ({ repo, mergedPrs, closedIssues }) => {
return [
`<h2><a href="https://github.com/${org}/${repo}">${repo}</a></h2>`,
...getItemsHtml('Merged PRs', mergedPrs),
...getItemsHtml('Closed issues', closedIssues),
...getItemsHtml("Merged PRs", mergedPrs),
...getItemsHtml("Closed issues", closedIssues),
]
}

Expand All @@ -143,19 +143,19 @@ const getRepoHtml = ({ repo, mergedPrs, closedIssues }) => {
* @returns {Promise} - the response for the POST request
*/
const postActivities = (activities) => {
const report = activities.map(getRepoHtml).flat().join('\n')
const report = activities.map(getRepoHtml).flat().join("\n")

const MAKE_SITE_API = 'https://make.wordpress.org/openverse/wp-json/wp/v2/'
const token = Buffer.from(`${username}:${password}`).toString('base64')
const MAKE_SITE_API = "https://make.wordpress.org/openverse/wp-json/wp/v2/"
const token = Buffer.from(`${username}:${password}`).toString("base64")

return axios.post(
'posts',
"posts",
{
title: `A week in Openverse: ${startDate} - ${endDate}`,
slug: `last-week-openverse-${startDate}-${endDate}`,
excerpt: `The developments in Openverse between ${startDate} and ${endDate}`,
content: report,
status: 'publish',
status: "publish",
tags: [
3, // openverse
5, // week-in-openverse
Expand Down Expand Up @@ -185,7 +185,7 @@ for (const repo of repos) {

const res = await postActivities(reportData)
if (res.status !== 201) {
console.error('Create post request failed. See the logs.')
console.error("Create post request failed. See the logs.")
process.exitCode = 1
}
console.log(JSON.stringify(res.data, null, 2))
Loading

0 comments on commit c68dcd6

Please sign in to comment.