From f13000f17b4ce23db1f72140b57cc485d34f916c Mon Sep 17 00:00:00 2001 From: Putta Khunchalee Date: Sun, 25 Feb 2024 00:08:05 +0700 Subject: [PATCH] Uses Python instead of JS on Housekeep Actions --- .github/workflows/main.yml | 33 ++++++++++----------------------- 1 file changed, 10 insertions(+), 23 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 5de61cc64..f9b4c1d67 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -18,30 +18,17 @@ jobs: name: Housekeep runs-on: ubuntu-latest steps: - - name: Install Node packages - run: sudo npm install -g octokit - name: Update PRs run: | - import { Octokit } from 'octokit'; + from datetime import datetime + from github import Auth, Github - const octokit = new Octokit({ auth: '${{ secrets.GITHUB_TOKEN }}' }); - const owner = '${{ github.event.repository.owner.login }}'; - const repo = '${{ github.event.repository.name }}'; - const resp = await octokit.request('GET /repos/{owner}/{repo}/pulls', { - owner, - repo, - base: '${{ github.ref_name }}', - sort: 'updated', - direction: 'desc', - per_page: 100, - }); + now = datetime.now() + gh = Github(auth=Auth.Token("${{ secrets.GITHUB_TOKEN }}")) + repo = gh.get_repo("${{ github.repository }}") - for (const pull of resp.data) { - await octokit.request('POST /repos/{owner}/{repo}/issues/{issue_number}/labels', { - owner, - repo, - issue_number: pull.number, - labels: ['B-out-of-date'], - }); - } - shell: node --experimental-default-type=module {0} + for pull in repo.get_pulls("open", "updated", "desc", "${{ github.ref_name }}"): + if (now - pull.updated_at).days > 30: + break + pull.add_to_labels("B-out-of-date") + shell: python