Openverse is a search engine for openly-licensed media. This monorepo includes all application code.
Automate the archiving of PRs in the PR board (#106)
Dhruv Bhanushali4e8a14131cd7
diff --git a/.github/GITHUB.md b/.github/GITHUB.mdindex 7c038042e..e73c4f3fb 100644--- a/.github/GITHUB.md+++ b/.github/GITHUB.md@@ -13,6 +13,14 @@ to the "In progress" column.**Cron:** [at every 15th minute](https://crontab.guru/#*/15_*_*_*_*)**Dispatch:** enabled+### PR project automation++This workflow archives PRs in the "Merged!" and "Closed" columns of the PR+project board, 15 minutes after the commencement of the weekly developer chat+at 15:00 UTC every Tuesday.++**Cron:** [at 15:15 on Tuesday](https://crontab.guru/#15_15_*_*_2)+### New issue automationThis workflow adds issues to the "Backlog" column in the Openverse project asdiff --git a/.github/workflows/label_sync.yml b/.github/workflows/label_sync.ymlindex b5e670c4f..1952395da 100644--- a/.github/workflows/label_sync.yml+++ b/.github/workflows/label_sync.yml@@ -21,7 +21,7 @@ jobs:- name: Setup Pythonuses: actions/setup-python@v2with:- python-version: 3.9+ python-version: "3.9"- name: Install dependenciesworking-directory: ./pythondiff --git a/.github/workflows/pr_project_automation.yml b/.github/workflows/pr_project_automation.ymlnew file mode 100644index 000000000..0216b5a73--- /dev/null+++ b/.github/workflows/pr_project_automation.yml@@ -0,0 +1,44 @@+name: PR project automation+# ℹ️ https://github.com/WordPress/openverse/blob/main/.github/GITHUB.md#pr-project-automation++on:+ schedule:+ - cron: "15 15 * * 2" # 3:15pm on Tuesday++env:+ LOGGING_LEVEL: 20 # corresponds to INFO+ ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }}++jobs:+ clear_done:+ name: Clear done PRs+ runs-on: ubuntu-latest+ steps:+ - name: Checkout repository+ uses: actions/checkout@v2++ - name: Setup Python+ uses: actions/setup-python@v2+ with:+ python-version: "3.9"++ - name: Install dependencies+ working-directory: ./python+ run: |+ python -m pip install --user --upgrade pip+ python -m pip install --user pipenv+ pipenv install --deploy++ - name: Clear PRs in "Merged!"+ working-directory: ./python+ run: |+ pipenv run python archive_column.py \+ --project-number 8 \+ --column "Merged\!"++ - name: Clear PRs in "Closed"+ working-directory: ./python+ run: |+ pipenv run python archive_column.py \+ --project-number 8 \+ --column "Closed"diff --git a/.github/workflows/project_automation.yml b/.github/workflows/project_automation.ymlindex 7095f6eb3..4d1b19f33 100644--- a/.github/workflows/project_automation.yml+++ b/.github/workflows/project_automation.yml@@ -21,7 +21,7 @@ jobs:- name: Setup Pythonuses: actions/setup-python@v2with:- python-version: 3.9+ python-version: "3.9"- name: Install dependenciesworking-directory: ./pythondiff --git a/python/archive_column.py b/python/archive_column.pynew file mode 100644index 000000000..7225b8571--- /dev/null+++ b/python/archive_column.py@@ -0,0 +1,64 @@+import argparse+import logging++from shared.data import get_data+from shared.github import get_client+from shared.log import configure_logger+from shared.project import get_org_project, get_project_column++log = logging.getLogger(__name__)++# region argparse+parser = argparse.ArgumentParser(+ description="Archive all cards in the given column of a project",+)+parser.add_argument(+ "--project-number",+ dest="proj_number",+ metavar="project-number",+ type=int,+ required=True,+ help="the project in which to the column to archive is located",+)+parser.add_argument(+ "--column",+ dest="col_name",+ metavar="column",+ type=str,+ required=True,+ help="column from which to archive the cards",+)+++# endregion+++def main():+ configure_logger()++ args = parser.parse_args()++ log.debug(f"Project number: {args.proj_number}")+ log.debug(f"Column name: {args.col_name}")++ github_info = get_data("github.yml")+ org_handle = github_info["org"]+ log.info(f"Organization handle: {org_handle}")++ gh = get_client()+ org = gh.get_organization(org_handle)++ proj = get_org_project(org=org, proj_number=args.proj_number)+ log.info(f"Found project: {proj.name}")+ column = get_project_column(proj=proj, col_name=args.col_name)+ log.debug("Found column")++ cards_to_archive = list(column.get_cards(archived_state="not archived"))+ log.info(f"Found {len(cards_to_archive)} cards")+ for card in cards_to_archive:+ card.edit(archived=True)+ log.info("Archived all cards in column")+++if __name__ == "__main__":+ main()