From 914ed6840bedf94c485b449a151d8a4862405c01 Mon Sep 17 00:00:00 2001 From: extremeheat Date: Sat, 9 Mar 2024 11:51:36 -0500 Subject: [PATCH] Move github-helper script to new gh-helpers (#485) --- .github/helper-bot/github-helper.js | 59 ----------------------------- .github/helper-bot/index.js | 2 +- .github/workflows/update-helper.yml | 4 +- 3 files changed, 3 insertions(+), 62 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 08759b2d..00000000 --- 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/bedrock-protocol' - 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 } -} diff --git a/.github/helper-bot/index.js b/.github/helper-bot/index.js index e9d58934..92317792 100644 --- a/.github/helper-bot/index.js +++ b/.github/helper-bot/index.js @@ -1,7 +1,7 @@ // Automatic version update checker for Minecraft bedrock edition. const fs = require('fs') const cp = require('child_process') -const helper = require('./github-helper') +const helper = require('gh-helpers') const latestVesionEndpoint = 'https://itunes.apple.com/lookup?bundleId=com.mojang.minecraftpe&time=' + Date.now() 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 84f2dfee..168dd044 100644 --- a/.github/workflows/update-helper.yml +++ b/.github/workflows/update-helper.yml @@ -15,8 +15,8 @@ jobs: uses: actions/setup-node@master with: node-version: 18.0.0 - - name: Install Github Actions toolkit - run: npm i @actions/github + - name: Install Github Actions helper + run: npm i gh-helpers # The env vars contain the relevant trigger information, so we don't need to pass it - name: Runs helper run: cd .github/helper-bot && node index.js