Skip to content

Commit 372a804

Browse files
committed
Use @actions/github instead of @octokit/core.
1 parent 356b5a6 commit 372a804

File tree

5 files changed

+53
-84
lines changed

5 files changed

+53
-84
lines changed

dist/cleanup/index.js

Lines changed: 18 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/main/index.js

Lines changed: 18 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
"@actions/http-client": "^2.2.3",
4242
"@actions/io": "^1.1.3",
4343
"@actions/tool-cache": "^2.0.2",
44-
"@octokit/core": "^5.2.0",
4544
"@octokit/types": "^14.1.0",
4645
"@github/dependency-submission-toolkit": "^2.0.5",
4746
"semver": "^7.7.2",

src/utils.ts

Lines changed: 17 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,15 @@
11
import * as c from './constants'
22
import * as core from '@actions/core'
33
import * as github from '@actions/github'
4-
import * as httpClient from '@actions/http-client'
54
import * as semver from 'semver'
65
import * as tc from '@actions/tool-cache'
76
import * as fs from 'fs'
87
import { ExecOptions, exec as e } from '@actions/exec'
98
import { readFileSync, readdirSync } from 'fs'
10-
import { Octokit } from '@octokit/core'
119
import { createHash } from 'crypto'
1210
import { join } from 'path'
1311
import { tmpdir } from 'os'
14-
15-
// Set up Octokit for github.com only and in the same way as @actions/github (see https://git.io/Jy9YP)
16-
const baseUrl = 'https://api.github.com'
17-
const GitHubDotCom = Octokit.defaults({
18-
baseUrl,
19-
request: {
20-
agent: new httpClient.HttpClient().getAgent(baseUrl)
21-
}
22-
})
12+
import { GitHub } from '@actions/github/lib/utils'
2313

2414
export async function exec(commandLine: string, args?: string[], options?: ExecOptions | undefined): Promise<void> {
2515
const exitCode = await e(commandLine, args, options)
@@ -29,9 +19,7 @@ export async function exec(commandLine: string, args?: string[], options?: ExecO
2919
}
3020

3121
export async function getLatestRelease(repo: string): Promise<c.LatestReleaseResponse['data']> {
32-
const githubToken = getGitHubToken()
33-
const options = githubToken.length > 0 ? { auth: githubToken } : {}
34-
const octokit = new GitHubDotCom(options)
22+
const octokit = getOctokit()
3523
return (
3624
await octokit.request('GET /repos/{owner}/{repo}/releases/latest', {
3725
owner: c.GRAALVM_GH_USER,
@@ -41,9 +29,7 @@ export async function getLatestRelease(repo: string): Promise<c.LatestReleaseRes
4129
}
4230

4331
export async function getContents(repo: string, path: string): Promise<c.ContentsResponse['data']> {
44-
const githubToken = getGitHubToken()
45-
const options = githubToken.length > 0 ? { auth: githubToken } : {}
46-
const octokit = new GitHubDotCom(options)
32+
const octokit = getOctokit()
4733
return (
4834
await octokit.request('GET /repos/{owner}/{repo}/contents/{path}', {
4935
owner: c.GRAALVM_GH_USER,
@@ -58,9 +44,7 @@ export async function getTaggedRelease(
5844
repo: string,
5945
tag: string
6046
): Promise<c.LatestReleaseResponse['data']> {
61-
const githubToken = getGitHubToken()
62-
const options = githubToken.length > 0 ? { auth: githubToken } : {}
63-
const octokit = new GitHubDotCom(options)
47+
const octokit = getOctokit()
6448
return (
6549
await octokit.request('GET /repos/{owner}/{repo}/releases/tags/{tag}', {
6650
owner,
@@ -75,9 +59,7 @@ export async function getMatchingTags(
7559
repo: string,
7660
tagPrefix: string
7761
): Promise<c.MatchingRefsResponse['data']> {
78-
const githubToken = getGitHubToken()
79-
const options = githubToken.length > 0 ? { auth: githubToken } : {}
80-
const octokit = new GitHubDotCom(options)
62+
const octokit = getOctokit()
8163
return (
8264
await octokit.request('GET /repos/{owner}/{repo}/git/matching-refs/tags/{tagPrefix}', {
8365
owner,
@@ -156,8 +138,15 @@ export function isPREvent(): boolean {
156138
return process.env[c.ENV_GITHUB_EVENT_NAME] === c.EVENT_NAME_PULL_REQUEST
157139
}
158140

159-
function getGitHubToken(): string {
160-
return core.getInput(c.INPUT_GITHUB_TOKEN)
141+
function getOctokit(): InstanceType<typeof GitHub> {
142+
/* Set up GitHub instance manually because @actions/github does not allow unauthenticated access */
143+
const GitHubWithPlugins = GitHub.plugin()
144+
const token = core.getInput(c.INPUT_GITHUB_TOKEN)
145+
if (token) {
146+
return new GitHubWithPlugins({ auth: `token ${token}` })
147+
} else {
148+
return new GitHubWithPlugins() /* unauthenticated */
149+
}
161150
}
162151

163152
export async function findExistingPRCommentId(bodyStartsWith: string): Promise<number | undefined> {
@@ -166,7 +155,7 @@ export async function findExistingPRCommentId(bodyStartsWith: string): Promise<n
166155
}
167156

168157
const context = github.context
169-
const octokit = github.getOctokit(getGitHubToken())
158+
const octokit = getOctokit()
170159
try {
171160
const comments = await octokit.paginate(octokit.rest.issues.listComments, {
172161
...context.repo,
@@ -189,7 +178,7 @@ export async function updatePRComment(content: string, commentId: number): Promi
189178
}
190179

191180
try {
192-
await github.getOctokit(getGitHubToken()).rest.issues.updateComment({
181+
await getOctokit().rest.issues.updateComment({
193182
...github.context.repo,
194183
comment_id: commentId,
195184
body: content
@@ -207,7 +196,7 @@ export async function createPRComment(content: string): Promise<void> {
207196
}
208197
const context = github.context
209198
try {
210-
await github.getOctokit(getGitHubToken()).rest.issues.createComment({
199+
await getOctokit().rest.issues.createComment({
211200
...context.repo,
212201
issue_number: context.payload.pull_request?.number as number,
213202
body: content

0 commit comments

Comments
 (0)