Skip to content

Commit 78a7266

Browse files
authored
Merge pull request #954 from marocchino/config-base-url
🔧 baseUrl config
2 parents f2c5111 + 87273ce commit 78a7266

File tree

6 files changed

+45
-4
lines changed

6 files changed

+45
-4
lines changed

__tests__/config.test.ts

+34
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
beforeEach(() => {
22
process.env["GITHUB_REPOSITORY"] = "marocchino/stick-pull-request-comment"
3+
process.env["INPUT_BASE_URL"] = "https://api.github.com"
34
process.env["INPUT_NUMBER"] = "123"
45
process.env["INPUT_APPEND"] = "false"
56
process.env["INPUT_RECREATE"] = "false"
@@ -18,6 +19,7 @@ beforeEach(() => {
1819
afterEach(() => {
1920
jest.resetModules()
2021
delete process.env["GITHUB_REPOSITORY"]
22+
delete process.env["INPUT_BASE_URL"]
2123
delete process.env["INPUT_OWNER"]
2224
delete process.env["INPUT_REPO"]
2325
delete process.env["INPUT_HEADER"]
@@ -38,10 +40,29 @@ afterEach(() => {
3840
delete process.env["INPUT_FOLLOW_SYMBOLIC_LINKS"]
3941
})
4042

43+
test("baseUrl", async () => {
44+
process.env["INPUT_BASE_URL"] = "https://repo.yourcompany.com"
45+
expect(require("../src/config")).toMatchObject({
46+
baseUrl: "https://repo.yourcompany.com",
47+
pullRequestNumber: expect.any(Number),
48+
repo: {owner: "marocchino", repo: "stick-pull-request-comment"},
49+
header: "",
50+
append: false,
51+
recreate: false,
52+
deleteOldComment: false,
53+
hideOldComment: false,
54+
hideAndRecreate: false,
55+
hideClassify: "OUTDATED",
56+
hideDetails: false,
57+
githubToken: "some-token",
58+
ignoreEmpty: false
59+
})
60+
})
4161
test("repo", async () => {
4262
process.env["INPUT_OWNER"] = "jin"
4363
process.env["INPUT_REPO"] = "other"
4464
expect(require("../src/config")).toMatchObject({
65+
baseUrl: "https://api.github.com",
4566
pullRequestNumber: expect.any(Number),
4667
repo: {owner: "jin", repo: "other"},
4768
header: "",
@@ -60,6 +81,7 @@ test("repo", async () => {
6081
test("header", async () => {
6182
process.env["INPUT_HEADER"] = "header"
6283
expect(require("../src/config")).toMatchObject({
84+
baseUrl: "https://api.github.com",
6385
pullRequestNumber: expect.any(Number),
6486
repo: {owner: "marocchino", repo: "stick-pull-request-comment"},
6587
header: "header",
@@ -78,6 +100,7 @@ test("header", async () => {
78100
test("append", async () => {
79101
process.env["INPUT_APPEND"] = "true"
80102
expect(require("../src/config")).toMatchObject({
103+
baseUrl: "https://api.github.com",
81104
pullRequestNumber: expect.any(Number),
82105
repo: {owner: "marocchino", repo: "stick-pull-request-comment"},
83106
header: "",
@@ -96,6 +119,7 @@ test("append", async () => {
96119
test("recreate", async () => {
97120
process.env["INPUT_RECREATE"] = "true"
98121
expect(require("../src/config")).toMatchObject({
122+
baseUrl: "https://api.github.com",
99123
pullRequestNumber: expect.any(Number),
100124
repo: {owner: "marocchino", repo: "stick-pull-request-comment"},
101125
header: "",
@@ -114,6 +138,7 @@ test("recreate", async () => {
114138
test("delete", async () => {
115139
process.env["INPUT_DELETE"] = "true"
116140
expect(require("../src/config")).toMatchObject({
141+
baseUrl: "https://api.github.com",
117142
pullRequestNumber: expect.any(Number),
118143
repo: {owner: "marocchino", repo: "stick-pull-request-comment"},
119144
header: "",
@@ -132,6 +157,7 @@ test("delete", async () => {
132157
test("hideOldComment", async () => {
133158
process.env["INPUT_HIDE"] = "true"
134159
expect(require("../src/config")).toMatchObject({
160+
baseUrl: "https://api.github.com",
135161
pullRequestNumber: expect.any(Number),
136162
repo: {owner: "marocchino", repo: "stick-pull-request-comment"},
137163
header: "",
@@ -150,6 +176,7 @@ test("hideOldComment", async () => {
150176
test("hideAndRecreate", async () => {
151177
process.env["INPUT_HIDE_AND_RECREATE"] = "true"
152178
expect(require("../src/config")).toMatchObject({
179+
baseUrl: "https://api.github.com",
153180
pullRequestNumber: expect.any(Number),
154181
repo: {owner: "marocchino", repo: "stick-pull-request-comment"},
155182
header: "",
@@ -168,6 +195,7 @@ test("hideAndRecreate", async () => {
168195
test("hideClassify", async () => {
169196
process.env["INPUT_HIDE_CLASSIFY"] = "OFF_TOPIC"
170197
expect(require("../src/config")).toMatchObject({
198+
baseUrl: "https://api.github.com",
171199
pullRequestNumber: expect.any(Number),
172200
repo: {owner: "marocchino", repo: "stick-pull-request-comment"},
173201
header: "",
@@ -186,6 +214,7 @@ test("hideClassify", async () => {
186214
test("hideDetails", async () => {
187215
process.env["INPUT_HIDE_DETAILS"] = "true"
188216
expect(require("../src/config")).toMatchObject({
217+
baseUrl: "https://api.github.com",
189218
pullRequestNumber: expect.any(Number),
190219
repo: {owner: "marocchino", repo: "stick-pull-request-comment"},
191220
header: "",
@@ -205,6 +234,7 @@ describe("path", () => {
205234
test("when exists return content of a file", async () => {
206235
process.env["INPUT_PATH"] = "./__tests__/assets/result"
207236
expect(require("../src/config")).toMatchObject({
237+
baseUrl: "https://api.github.com",
208238
pullRequestNumber: expect.any(Number),
209239
repo: {owner: "marocchino", repo: "stick-pull-request-comment"},
210240
header: "",
@@ -224,6 +254,7 @@ describe("path", () => {
224254
test("glob match files", async () => {
225255
process.env["INPUT_PATH"] = "./__tests__/assets/*"
226256
expect(require("../src/config")).toMatchObject({
257+
baseUrl: "https://api.github.com",
227258
pullRequestNumber: expect.any(Number),
228259
repo: {owner: "marocchino", repo: "stick-pull-request-comment"},
229260
header: "",
@@ -245,6 +276,7 @@ describe("path", () => {
245276
test("when not exists return null string", async () => {
246277
process.env["INPUT_PATH"] = "./__tests__/assets/not_exists"
247278
expect(require("../src/config")).toMatchObject({
279+
baseUrl: "https://api.github.com",
248280
pullRequestNumber: expect.any(Number),
249281
repo: {owner: "marocchino", repo: "stick-pull-request-comment"},
250282
header: "",
@@ -265,6 +297,7 @@ describe("path", () => {
265297
test("message", async () => {
266298
process.env["INPUT_MESSAGE"] = "hello there"
267299
expect(require("../src/config")).toMatchObject({
300+
baseUrl: "https://api.github.com",
268301
pullRequestNumber: expect.any(Number),
269302
repo: {owner: "marocchino", repo: "stick-pull-request-comment"},
270303
header: "",
@@ -284,6 +317,7 @@ test("message", async () => {
284317
test("ignore_empty", async () => {
285318
process.env["INPUT_IGNORE_EMPTY"] = "true"
286319
expect(require("../src/config")).toMatchObject({
320+
baseUrl: "https://api.github.com",
287321
pullRequestNumber: expect.any(Number),
288322
repo: {owner: "marocchino", repo: "stick-pull-request-comment"},
289323
header: "",

action.yml

+4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ github-token:
1111
pull-requests-reason: to create or update PR comment
1212

1313
inputs:
14+
base_url:
15+
description: "base api url. default to: https://api.github.com"
16+
default: "https://api.github.com"
17+
required: false
1418
header:
1519
description: "Header to determine if the comment is to be updated, not shown on screen. It can be used when you want to add multiple comments independently at the same time."
1620
default: ""

dist/index.js

+3-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/config.ts

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export const pullRequestNumber =
88
context?.payload?.pull_request?.number ||
99
+core.getInput("number", {required: false})
1010

11+
export const baseUrl = core.getInput("base_url", {required: true})
1112
export const repo = buildRepo()
1213
export const header = core.getInput("header", {required: false})
1314
export const append = core.getBooleanInput("append", {required: true})

src/main.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as github from "@actions/github"
33
import {
44
append,
55
getBody,
6+
baseUrl,
67
deleteOldComment,
78
githubToken,
89
header,
@@ -56,7 +57,7 @@ async function run(): Promise<undefined> {
5657
throw new Error("hide and hide_and_recreate cannot be both set to true")
5758
}
5859

59-
const octokit = github.getOctokit(githubToken)
60+
const octokit = github.getOctokit(githubToken, {baseUrl})
6061
const previous = await findPreviousComment(
6162
octokit,
6263
repo,

0 commit comments

Comments
 (0)