Move github-helper script to new gh-helpers (#485)
This commit is contained in:
parent
ab93d0d082
commit
914ed6840b
3 changed files with 3 additions and 62 deletions
59
.github/helper-bot/github-helper.js
vendored
59
.github/helper-bot/github-helper.js
vendored
|
|
@ -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 }
|
||||
}
|
||||
2
.github/helper-bot/index.js
vendored
2
.github/helper-bot/index.js
vendored
|
|
@ -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'
|
||||
|
||||
|
|
|
|||
4
.github/workflows/update-helper.yml
vendored
4
.github/workflows/update-helper.yml
vendored
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue