Openverse is a search engine for openly-licensed media. This monorepo includes all application code.
Project thread reminders (#2251)
Zack Krida9c739b159036
diff --git a/.github/workflows/project_thread_update_reminders.yml b/.github/workflows/project_thread_update_reminders.ymlindex 08493f153..b54181ce7 100644--- a/.github/workflows/project_thread_update_reminders.yml+++ b/.github/workflows/project_thread_update_reminders.yml@@ -1,32 +1,18 @@-# This workflow is currently a stub to allow for testing the-# project thread update action manually in the GitHub UI.-# Actions must be present in the main branch to appear there.name: Project Thread Update Reminderson:- workflow_dispatch:- inputs:- dry_run:- type: boolean- description: "Dry run"- required: true- default: true+ schedule:+ # Run every day at 00:00 UTC+ - cron: "0 0 * * *"jobs:- check:+ send-reminders:runs-on: ubuntu-lateststeps:- - name: Checkout code- uses: actions/checkout@v3-- - name: Set up Node.js- uses: actions/setup-node@v3+ - uses: actions/checkout@v3+ - uses: actions/github-script@v6with:- node-version: "16"-- - name: Run project thread check- run: node ./src/project_thread_updates.js- working-directory: ./automations/js- env:- GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}- DRY_RUN: ${{ inputs.dry_run }}+ github-token: ${{ secrets.ACCESS_TOKEN }}+ script: |+ const script = require('./automations/js/src/project_thread_updates.js')+ await script({github, core})diff --git a/automations/js/package.json b/automations/js/package.jsonindex 99ba2bca7..6e7a31527 100644--- a/automations/js/package.json+++ b/automations/js/package.json@@ -9,5 +9,9 @@"js-yaml": "^4.1.0","k6": "0.0.0","nunjucks": "^3.2.3"+ },+ "devDependencies": {+ "@actions/core": "^1.10.0",+ "@actions/github": "^5.1.1"}}diff --git a/automations/js/src/project_thread_updates.js b/automations/js/src/project_thread_updates.jsindex 7db8f99da..2af8a6cbb 100644--- a/automations/js/src/project_thread_updates.js+++ b/automations/js/src/project_thread_updates.js@@ -1,11 +1,120 @@-// const github = require('@actions/github')-const core = require('@actions/core')--async function run() {- const isDryRun = core.getBooleanInput('dry_run') ?? false- core.info(`Dry run status: ${isDryRun}`)- core.info('Success.')- return true-}+// @ts-check++const activeDevelopmentStatuses = [+ 'In Kickoff',+ 'In RFC',+ 'In Progress',+ 'Shipped',+]++const GET_PROJECT_CARDS = `+ query($repo: String!, $repoOwner: String!, $projectBoardID: Int!, $projectStatusColumnName: String!) {+ repository(name: $repo, owner: $repoOwner) {+ projectV2(number: $projectBoardID) {+ items(last: 100) {+ nodes {+ id+ fieldValueByName(name: $projectStatusColumnName) {+ ... on ProjectV2ItemFieldSingleSelectValue {+ name+ }+ }+ content {+ __typename+ ... on Issue {+ id+ url+ state+ assignees(first: 10) {+ nodes {+ login+ }+ }+ author {+ login+ }+ comments(last: 100) {+ nodes {+ createdAt+ }+ }+ }+ }+ }+ }+ }+ }+ }+`++/**+ * Check our GitHub project board cards for attached "project thread" issues.+ * Check the issues to see if they've been commented on in the correct timeframe;+ * if not notify the project lead.+ *+ * @param {Object} options+ * @param {import('@octokit/rest').Octokit} options.github+ * @param {import('@actions/core')} options.core+ */+module.exports = async ({ github, core }) => {+ try {+ const isDryRun = process.env.DRY_RUN === 'true' ?? false++ const currentDate = new Date()+ const fourteenDaysAgo = new Date(+ currentDate.getFullYear(),+ currentDate.getMonth(),+ currentDate.getDate() - 14+ )++ // Fetch project cards with their associated issue data+ const result = await github.graphql(GET_PROJECT_CARDS, {+ projectBoardID: 70,+ projectStatusColumnName: 'Status',+ repoOwner: 'wordpress',+ repo: 'openverse',+ })++ for (const node of result.repository.projectV2.items.nodes) {+ const issue = node.content+ // If we're not looking at an open issue, move along+ if (issue.__typename !== 'Issue' || issue.state !== 'OPEN') continue-run()+ // Check the status of the card to make sure the project is in active development+ const status = node.fieldValueByName.name+ if (!activeDevelopmentStatuses.includes(status)) continue++ const comments = issue.comments.nodes++ if (+ // Check if the issue has been commented on in the last 14 days+ !comments.some(+ (comment) => new Date(comment.createdAt) > fourteenDaysAgo+ )+ ) {+ // If not, leave a reminder comment on the issue+ const recipient = issue.assignees.nodes[0]+ ? issue.assignees.nodes[0].login+ : issue.author.login++ const body = `Hi @${recipient}, this project has not received an update comment in 14 days. Please leave an update comment as soon as you can. See the [documentation on project updates](https://docs.openverse.org/projects/planning.html#providing-project-updates) for more information.`++ if (isDryRun) {+ core.info(`Would have commented on issue ${issue.url}: ${body}`)+ } else {+ // Extract the owner, repo, and issue number from the issue URL+ const [, , , owner, repo, , issue_number] = issue.url.split('/')++ await github.rest.issues.createComment({+ owner,+ repo,+ issue_number,+ body,+ })+ }+ }+ }+ } catch (error) {+ core.setFailed(error.message)+ }+}diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex 5505db851..1de75cd9f 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -7,6 +7,8 @@ importers:automations/js:specifiers:+ '@actions/core': ^1.10.0+ '@actions/github': ^5.1.1'@octokit/rest': 19.0.7axios: ^0.27.0js-yaml: ^4.1.0@@ -18,6 +20,9 @@ importers:js-yaml: 4.1.0k6: 0.0.0nunjucks: 3.2.3+ devDependencies:+ '@actions/core': 1.10.0+ '@actions/github': 5.1.1frontend:specifiers:@@ -246,6 +251,30 @@ importers:packages:+ /@actions/core/1.10.0:+ resolution: {integrity: sha512-2aZDDa3zrrZbP5ZYg159sNoLRb61nQ7awl5pSvIq5Qpj81vwDzdMRKzkWJGJuwVvWpvZKx7vspJALyvaaIQyug==}+ dependencies:+ '@actions/http-client': 2.1.0+ uuid: 8.3.2+ dev: true++ /@actions/github/5.1.1:+ resolution: {integrity: sha512-Nk59rMDoJaV+mHCOJPXuvB1zIbomlKS0dmSIqPGxd0enAXBnOfn4VWF+CGtRCwXZG9Epa54tZA7VIRlJDS8A6g==}+ dependencies:+ '@actions/http-client': 2.1.0+ '@octokit/core': 3.6.0+ '@octokit/plugin-paginate-rest': 2.21.3_@[email protected]+ '@octokit/plugin-rest-endpoint-methods': 5.16.2_@[email protected]+ transitivePeerDependencies:+ - encoding+ dev: true++ /@actions/http-client/2.1.0:+ resolution: {integrity: sha512-BonhODnXr3amchh4qkmjPMUO8mFi/zLaaCeCAJZqch8iQqyDnVIkySjB38VHAC8IJ+bnlgfOqlhpyCUZHlQsqw==}+ dependencies:+ tunnel: 0.0.6+ dev: true+/@ampproject/remapping/2.1.2:resolution: {integrity: sha512-hoyByceqwKirw7w3Z7gnIIZC3Wx3J484Y3L/cMpXFbr7d9ZQj2mODrirNzcJa+SM3UlpWXYvKV4RlRpFXlWgXg==}engines: {node: '>=6.0.0'}@@ -4370,6 +4399,12 @@ packages:stack-trace: 0.0.10dev: false+ /@octokit/auth-token/2.5.0:+ resolution: {integrity: sha512-r5FVUJCOLl19AxiuZD2VRZ/ORjp/4IN98Of6YJoJOkY75CIBuYfmiNHGrDwXr+aLGG55igl9QrxX3hbiXlLb+g==}+ dependencies:+ '@octokit/types': 6.41.0+ dev: true+/@octokit/auth-token/3.0.3:resolution: {integrity: sha512-/aFM2M4HVDBT/jjDBa84sJniv1t9Gm/rLkalaz9htOm+L+8JMj1k9w0CkUdcxNyNxZPlTxKPVko+m1VlM58ZVA==}engines: {node: '>= 14'}@@ -4377,6 +4412,20 @@ packages:'@octokit/types': 9.0.0dev: false+ /@octokit/core/3.6.0:+ resolution: {integrity: sha512-7RKRKuA4xTjMhY+eG3jthb3hlZCsOwg3rztWh75Xc+ShDWOfDDATWbeZpAHBNRpm4Tv9WgBMOy1zEJYXG6NJ7Q==}+ dependencies:+ '@octokit/auth-token': 2.5.0+ '@octokit/graphql': 4.8.0+ '@octokit/request': 5.6.3+ '@octokit/request-error': 2.1.0+ '@octokit/types': 6.41.0+ before-after-hook: 2.2.3+ universal-user-agent: 6.0.0+ transitivePeerDependencies:+ - encoding+ dev: true+/@octokit/core/4.2.0:resolution: {integrity: sha512-AgvDRUg3COpR82P7PBdGZF/NNqGmtMq2NiPqeSsDIeCfYFOZ9gddqWNQHnFdEUf+YwOj4aZYmJnlPp7OXmDIDg==}engines: {node: '>= 14'}@@ -4392,6 +4441,14 @@ packages:- encodingdev: false+ /@octokit/endpoint/6.0.12:+ resolution: {integrity: sha512-lF3puPwkQWGfkMClXb4k/eUT/nZKQfxinRWJrdZaJO85Dqwo/G0yOC434Jr2ojwafWJMYqFGFa5ms4jJUgujdA==}+ dependencies:+ '@octokit/types': 6.41.0+ is-plain-object: 5.0.0+ universal-user-agent: 6.0.0+ dev: true+/@octokit/endpoint/7.0.5:resolution: {integrity: sha512-LG4o4HMY1Xoaec87IqQ41TQ+glvIeTKqfjkCEmt5AIwDZJwQeVZFIEYXrYY6yLwK+pAScb9Gj4q+Nz2qSw1roA==}engines: {node: '>= 14'}@@ -4401,6 +4458,16 @@ packages:universal-user-agent: 6.0.0dev: false+ /@octokit/graphql/4.8.0:+ resolution: {integrity: sha512-0gv+qLSBLKF0z8TKaSKTsS39scVKF9dbMxJpj3U0vC7wjNWFuIpL/z76Qe2fiuCbDRcJSavkXsVtMS6/dtQQsg==}+ dependencies:+ '@octokit/request': 5.6.3+ '@octokit/types': 6.41.0+ universal-user-agent: 6.0.0+ transitivePeerDependencies:+ - encoding+ dev: true+/@octokit/graphql/5.0.5:resolution: {integrity: sha512-Qwfvh3xdqKtIznjX9lz2D458r7dJPP8l6r4GQkIdWQouZwHQK0mVT88uwiU2bdTU2OtT1uOlKpRciUWldpG0yQ==}engines: {node: '>= 14'}@@ -4412,10 +4479,23 @@ packages:- encodingdev: false+ /@octokit/openapi-types/12.11.0:+ resolution: {integrity: sha512-VsXyi8peyRq9PqIz/tpqiL2w3w80OgVMwBHltTml3LmVvXiphgeqmY9mvBw9Wu7e0QWk/fqD37ux8yP5uVekyQ==}+ dev: true+/@octokit/openapi-types/16.0.0:resolution: {integrity: sha512-JbFWOqTJVLHZSUUoF4FzAZKYtqdxWu9Z5m2QQnOyEa04fOFljvyh7D3GYKbfuaSWisqehImiVIMG4eyJeP5VEA==}dev: false+ /@octokit/plugin-paginate-rest/2.21.3_@[email protected]:+ resolution: {integrity: sha512-aCZTEf0y2h3OLbrgKkrfFdjRL6eSOo8komneVQJnYecAxIej7Bafor2xhuDJOIFau4pk0i/P28/XgtbyPF0ZHw==}+ peerDependencies:+ '@octokit/core': '>=2'+ dependencies:+ '@octokit/core': 3.6.0+ '@octokit/types': 6.41.0+ dev: true+/@octokit/plugin-paginate-rest/6.0.0_@[email protected]:resolution: {integrity: sha512-Sq5VU1PfT6/JyuXPyt04KZNVsFOSBaYOAq2QRZUwzVlI10KFvcbUo8lR258AAQL1Et60b0WuVik+zOWKLuDZxw==}engines: {node: '>= 14'}@@ -4434,6 +4514,16 @@ packages:'@octokit/core': 4.2.0dev: false+ /@octokit/plugin-rest-endpoint-methods/5.16.2_@[email protected]:+ resolution: {integrity: sha512-8QFz29Fg5jDuTPXVtey05BLm7OB+M8fnvE64RNegzX7U+5NUXcOcnpTIK0YfSHBg8gYd0oxIq3IZTe9SfPZiRw==}+ peerDependencies:+ '@octokit/core': '>=3'+ dependencies:+ '@octokit/core': 3.6.0+ '@octokit/types': 6.41.0+ deprecation: 2.3.1+ dev: true+/@octokit/plugin-rest-endpoint-methods/7.0.1_@[email protected]:resolution: {integrity: sha512-pnCaLwZBudK5xCdrR823xHGNgqOzRnJ/mpC/76YPpNP7DybdsJtP7mdOwh+wYZxK5jqeQuhu59ogMI4NRlBUvA==}engines: {node: '>= 14'}@@ -4445,6 +4535,14 @@ packages:deprecation: 2.3.1dev: false+ /@octokit/request-error/2.1.0:+ resolution: {integrity: sha512-1VIvgXxs9WHSjicsRwq8PlR2LR2x6DwsJAaFgzdi0JfJoGSO8mYI/cHJQ+9FbN21aa+DrgNLnwObmyeSC8Rmpg==}+ dependencies:+ '@octokit/types': 6.41.0+ deprecation: 2.3.1+ once: 1.4.0+ dev: true+/@octokit/request-error/3.0.3:resolution: {integrity: sha512-crqw3V5Iy2uOU5Np+8M/YexTlT8zxCfI+qu+LxUB7SZpje4Qmx3mub5DfEKSO8Ylyk0aogi6TYdf6kxzh2BguQ==}engines: {node: '>= 14'}@@ -4454,6 +4552,19 @@ packages:once: 1.4.0dev: false+ /@octokit/request/5.6.3:+ resolution: {integrity: sha512-bFJl0I1KVc9jYTe9tdGGpAMPy32dLBXXo1dS/YwSCTL/2nd9XeHsY616RE3HPXDVk+a+dBuzyz5YdlXwcDTr2A==}+ dependencies:+ '@octokit/endpoint': 6.0.12+ '@octokit/request-error': 2.1.0+ '@octokit/types': 6.41.0+ is-plain-object: 5.0.0+ node-fetch: 2.6.7+ universal-user-agent: 6.0.0+ transitivePeerDependencies:+ - encoding+ dev: true+/@octokit/request/6.2.3:resolution: {integrity: sha512-TNAodj5yNzrrZ/VxP+H5HiYaZep0H3GU0O7PaF+fhDrt8FPrnkei9Aal/txsN/1P7V3CPiThG0tIvpPDYUsyAA==}engines: {node: '>= 14'}@@ -4480,6 +4591,12 @@ packages:- encodingdev: false+ /@octokit/types/6.41.0:+ resolution: {integrity: sha512-eJ2jbzjdijiL3B4PrSQaSjuF2sPEQPVCPzBvTHJD9Nz+9dw2SGH4K4xeQJ77YfTq5bRQ+bD8wT11JbeDPmxmGg==}+ dependencies:+ '@octokit/openapi-types': 12.11.0+ dev: true+/@octokit/types/9.0.0:resolution: {integrity: sha512-LUewfj94xCMH2rbD5YJ+6AQ4AVjFYTgpp6rboWM5T7N3IsIF65SBEOVcYMGAEzO/kKNiNaW4LoWtoThOhH06gw==}dependencies:@@ -8104,7 +8221,6 @@ packages:/before-after-hook/2.2.3:resolution: {integrity: sha512-NzUnlZexiaH/46WDhANlyR2bXRopNg4F/zuSA3OpZnllCUgRaOF2znDioDWrmbNVsuZk6l9pMquQB38cfBZwkQ==}- dev: false/better-opn/2.1.1:resolution: {integrity: sha512-kIPXZS5qwyKiX/HcRvDYfmBQUa8XP17I0mYZZ0y4UhpYOSvtsLHDYqmomS+Mj20aDvD3knEiQ0ecQy2nhio3yA==}@@ -9946,7 +10062,6 @@ packages:/deprecation/2.3.1:resolution: {integrity: sha512-xmHIy4F3scKVwMsQ4WnVaS8bHOx0DmVwRywosKhaILI0ywMDWPtBSku2HNxRvF7jtwDRsoEwYQSfbxj8b7RlJQ==}- dev: false/des.js/1.0.1:resolution: {integrity: sha512-Q0I4pfFrv2VPd34/vfLrFOoRmlYj3OV50i7fskps1jZWK1kApMWWT9G6RRUeYedLcBDIhnSDaUvJMb3AhUlaEA==}@@ -12530,7 +12645,6 @@ packages:/is-plain-object/5.0.0:resolution: {integrity: sha512-VRSzKkbMm5jMDoKLbltAkFQ5Qr7VDiTFGXxYFXXowVj387GeGNOCsOH6Msy00SGZ3Fp84b1Naa1psqgcCIEP5Q==}engines: {node: '>=0.10.0'}- dev: false/is-potential-custom-element-name/1.0.1:resolution: {integrity: sha512-bCYeRA2rVibKZd+s2625gGnGF/t7DSqDs4dP7CrLA1m7jKWz6pps0LpYLJN8Q64HtmPKJ1hrN3nzPNKFEKOUiQ==}@@ -18507,6 +18621,11 @@ packages:/tty-browserify/0.0.0:resolution: {integrity: sha512-JVa5ijo+j/sOoHGjw0sxw734b1LhBkQ3bvUGNdxnVXDCX81Yx7TFgnZygxrIIWn23hbfTaMYLwRmAxFyDuFmIw==}+ /tunnel/0.0.6:+ resolution: {integrity: sha512-1h/Lnq9yajKY2PEbBadPXj3VxsDDu844OnaAo52UVmIzIvwwtBPIuNvkjuzBlTWpfJyUbG3ez0KSBibQkj4ojg==}+ engines: {node: '>=0.6.11 <=0.7.0 || >=0.7.3'}+ dev: true+/type-check/0.3.2:resolution: {integrity: sha512-ZCmOJdvOWDBYJlzAoFkC+Q0+bUyEOS1ltgp1MGU03fqHG+dbi9tBFU2Rd9QKiDZFAYrhPh2JUf7rZRIuHRKtOg==}engines: {node: '>= 0.8.0'}@@ -18724,7 +18843,6 @@ packages:/universal-user-agent/6.0.0:resolution: {integrity: sha512-isyNax3wXoKaulPDZWHQqbmIx1k2tb9fb3GGDBRxCscfYV2Ch7WxPArBsFEG8s/safwXTT7H4QGhaIkTp9447w==}- dev: false/universalify/0.1.2:resolution: {integrity: sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg==}