From cee858b4367303b21dae7101cc7a8c6c34ec83da Mon Sep 17 00:00:00 2001 From: extremeheat Date: Sat, 9 Mar 2024 11:50:37 -0500 Subject: [PATCH] Move github-helper script to new gh-helpers (#855) --- .github/helper-bot/github-helper.js | 59 ----------------------------- .github/helper-bot/index.js | 2 +- .github/workflows/update-helper.yml | 2 +- 3 files changed, 2 insertions(+), 61 deletions(-) delete mode 100644 .github/helper-bot/github-helper.js diff --git a/.github/helper-bot/github-helper.js b/.github/helper-bot/github-helper.js deleted file mode 100644 index 82537a520..000000000 --- a/.github/helper-bot/github-helper.js +++ /dev/null @@ -1,59 +0,0 @@ -if (!process.env.CI) { - // mock a bunch of things for testing locally -- https://github.com/actions/toolkit/issues/71 - process.env.GITHUB_REPOSITORY = 'PrismarineJS/minecraft-data' - process.env.GITHUB_EVENT_NAME = 'issue_comment' - process.env.GITHUB_SHA = 'cb2fd97b6eae9f2c7fee79d5a86eb9c3b4ac80d8' - process.env.GITHUB_REF = 'refs/heads/master' - process.env.GITHUB_WORKFLOW = 'Issue comments' - process.env.GITHUB_ACTION = 'run1' - process.env.GITHUB_ACTOR = 'test-user' - module.exports = { getIssueStatus: () => ({}), updateIssue: () => {}, createIssue: () => {} } - return -} - -// const { Octokit } = require('@octokit/rest') // https://github.com/octokit/rest.js -const github = require('@actions/github') - -const token = process.env.GITHUB_TOKEN -const octokit = github.getOctokit(token) -const context = github.context - -async function getIssueStatus (title) { - // https://docs.github.com/en/rest/reference/search#search-issues-and-pull-requests - const existingIssues = await octokit.rest.search.issuesAndPullRequests({ - q: `is:issue repo:${process.env.GITHUB_REPOSITORY} in:title ${title}` - }) - // console.log('Existing issues', existingIssues) - const existingIssue = existingIssues.data.items.find(issue => issue.title === title) - - if (!existingIssue) return {} - - return { open: existingIssue.state === 'open', closed: existingIssue.state === 'closed', id: existingIssue.number } -} - -async function updateIssue (id, payload) { - const issue = await octokit.rest.issues.update({ - ...context.repo, - issue_number: id, - body: payload.body - }) - console.log(`Updated issue ${issue.data.title}#${issue.data.number}: ${issue.data.html_url}`) -} - -async function createIssue (payload) { - const issue = await octokit.rest.issues.create({ - ...context.repo, - ...payload - }) - console.log(`Created issue ${issue.data.title}#${issue.data.number}: ${issue.data.html_url}`) -} - -async function close (id, reason) { - if (reason) await octokit.rest.issues.createComment({ ...context.repo, issue_number: id, body: reason }) - const issue = await octokit.rest.issues.update({ ...context.repo, issue_number: id, state: 'closed' }) - console.log(`Closed issue ${issue.data.title}#${issue.data.number}: ${issue.data.html_url}`) -} - -if (process.env.CI) { - module.exports = { getIssueStatus, updateIssue, createIssue, close } -} \ No newline at end of file diff --git a/.github/helper-bot/index.js b/.github/helper-bot/index.js index f89449fe3..fb268d31f 100644 --- a/.github/helper-bot/index.js +++ b/.github/helper-bot/index.js @@ -1,6 +1,6 @@ const fs = require('fs') const cp = require('child_process') -const helper = require('./github-helper') +const helper = require('gh-helpers') const pcManifestURL = 'https://launchermeta.mojang.com/mc/game/version_manifest.json' const changelogURL = 'https://feedback.minecraft.net/hc/en-us/sections/360001186971-Release-Changelogs' diff --git a/.github/workflows/update-helper.yml b/.github/workflows/update-helper.yml index 96c71b521..06f44623b 100644 --- a/.github/workflows/update-helper.yml +++ b/.github/workflows/update-helper.yml @@ -16,7 +16,7 @@ jobs: with: node-version: 18.0.0 - name: Install Github Actions toolkit - run: npm i @actions/github + run: npm i gh-helpers working-directory: .github/helper-bot # The env vars contain the relevant trigger information, so we don't need to pass it - name: Runs helper