mirror of
https://github.com/marocchino/sticky-pull-request-comment.git
synced 2025-12-13 04:01:14 +00:00
🔧 baseUrl config
The `baseUrl`, which could be taken as an input, is required to use a custom GitHub Enterprise URL, for example.
This commit is contained in:
parent
f2c5111552
commit
292f33e766
4 changed files with 41 additions and 1 deletions
|
|
@ -1,5 +1,6 @@
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
process.env["GITHUB_REPOSITORY"] = "marocchino/stick-pull-request-comment"
|
process.env["GITHUB_REPOSITORY"] = "marocchino/stick-pull-request-comment"
|
||||||
|
process.env["INPUT_BASE_URL"] = "https://api.github.com"
|
||||||
process.env["INPUT_NUMBER"] = "123"
|
process.env["INPUT_NUMBER"] = "123"
|
||||||
process.env["INPUT_APPEND"] = "false"
|
process.env["INPUT_APPEND"] = "false"
|
||||||
process.env["INPUT_RECREATE"] = "false"
|
process.env["INPUT_RECREATE"] = "false"
|
||||||
|
|
@ -18,6 +19,7 @@ beforeEach(() => {
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
jest.resetModules()
|
jest.resetModules()
|
||||||
delete process.env["GITHUB_REPOSITORY"]
|
delete process.env["GITHUB_REPOSITORY"]
|
||||||
|
delete process.env["INPUT_BASE_URL"]
|
||||||
delete process.env["INPUT_OWNER"]
|
delete process.env["INPUT_OWNER"]
|
||||||
delete process.env["INPUT_REPO"]
|
delete process.env["INPUT_REPO"]
|
||||||
delete process.env["INPUT_HEADER"]
|
delete process.env["INPUT_HEADER"]
|
||||||
|
|
@ -38,10 +40,29 @@ afterEach(() => {
|
||||||
delete process.env["INPUT_FOLLOW_SYMBOLIC_LINKS"]
|
delete process.env["INPUT_FOLLOW_SYMBOLIC_LINKS"]
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test("baseUrl", async () => {
|
||||||
|
process.env["INPUT_BASE_URL"] = "https://repo.yourcompany.com"
|
||||||
|
expect(require("../src/config")).toMatchObject({
|
||||||
|
baseUrl: "https://repo.yourcompany.com",
|
||||||
|
pullRequestNumber: expect.any(Number),
|
||||||
|
repo: {owner: "marocchino", repo: "stick-pull-request-comment"},
|
||||||
|
header: "",
|
||||||
|
append: false,
|
||||||
|
recreate: false,
|
||||||
|
deleteOldComment: false,
|
||||||
|
hideOldComment: false,
|
||||||
|
hideAndRecreate: false,
|
||||||
|
hideClassify: "OUTDATED",
|
||||||
|
hideDetails: false,
|
||||||
|
githubToken: "some-token",
|
||||||
|
ignoreEmpty: false
|
||||||
|
})
|
||||||
|
})
|
||||||
test("repo", async () => {
|
test("repo", async () => {
|
||||||
process.env["INPUT_OWNER"] = "jin"
|
process.env["INPUT_OWNER"] = "jin"
|
||||||
process.env["INPUT_REPO"] = "other"
|
process.env["INPUT_REPO"] = "other"
|
||||||
expect(require("../src/config")).toMatchObject({
|
expect(require("../src/config")).toMatchObject({
|
||||||
|
baseUrl: "https://api.github.com",
|
||||||
pullRequestNumber: expect.any(Number),
|
pullRequestNumber: expect.any(Number),
|
||||||
repo: {owner: "jin", repo: "other"},
|
repo: {owner: "jin", repo: "other"},
|
||||||
header: "",
|
header: "",
|
||||||
|
|
@ -60,6 +81,7 @@ test("repo", async () => {
|
||||||
test("header", async () => {
|
test("header", async () => {
|
||||||
process.env["INPUT_HEADER"] = "header"
|
process.env["INPUT_HEADER"] = "header"
|
||||||
expect(require("../src/config")).toMatchObject({
|
expect(require("../src/config")).toMatchObject({
|
||||||
|
baseUrl: "https://api.github.com",
|
||||||
pullRequestNumber: expect.any(Number),
|
pullRequestNumber: expect.any(Number),
|
||||||
repo: {owner: "marocchino", repo: "stick-pull-request-comment"},
|
repo: {owner: "marocchino", repo: "stick-pull-request-comment"},
|
||||||
header: "header",
|
header: "header",
|
||||||
|
|
@ -78,6 +100,7 @@ test("header", async () => {
|
||||||
test("append", async () => {
|
test("append", async () => {
|
||||||
process.env["INPUT_APPEND"] = "true"
|
process.env["INPUT_APPEND"] = "true"
|
||||||
expect(require("../src/config")).toMatchObject({
|
expect(require("../src/config")).toMatchObject({
|
||||||
|
baseUrl: "https://api.github.com",
|
||||||
pullRequestNumber: expect.any(Number),
|
pullRequestNumber: expect.any(Number),
|
||||||
repo: {owner: "marocchino", repo: "stick-pull-request-comment"},
|
repo: {owner: "marocchino", repo: "stick-pull-request-comment"},
|
||||||
header: "",
|
header: "",
|
||||||
|
|
@ -96,6 +119,7 @@ test("append", async () => {
|
||||||
test("recreate", async () => {
|
test("recreate", async () => {
|
||||||
process.env["INPUT_RECREATE"] = "true"
|
process.env["INPUT_RECREATE"] = "true"
|
||||||
expect(require("../src/config")).toMatchObject({
|
expect(require("../src/config")).toMatchObject({
|
||||||
|
baseUrl: "https://api.github.com",
|
||||||
pullRequestNumber: expect.any(Number),
|
pullRequestNumber: expect.any(Number),
|
||||||
repo: {owner: "marocchino", repo: "stick-pull-request-comment"},
|
repo: {owner: "marocchino", repo: "stick-pull-request-comment"},
|
||||||
header: "",
|
header: "",
|
||||||
|
|
@ -114,6 +138,7 @@ test("recreate", async () => {
|
||||||
test("delete", async () => {
|
test("delete", async () => {
|
||||||
process.env["INPUT_DELETE"] = "true"
|
process.env["INPUT_DELETE"] = "true"
|
||||||
expect(require("../src/config")).toMatchObject({
|
expect(require("../src/config")).toMatchObject({
|
||||||
|
baseUrl: "https://api.github.com",
|
||||||
pullRequestNumber: expect.any(Number),
|
pullRequestNumber: expect.any(Number),
|
||||||
repo: {owner: "marocchino", repo: "stick-pull-request-comment"},
|
repo: {owner: "marocchino", repo: "stick-pull-request-comment"},
|
||||||
header: "",
|
header: "",
|
||||||
|
|
@ -132,6 +157,7 @@ test("delete", async () => {
|
||||||
test("hideOldComment", async () => {
|
test("hideOldComment", async () => {
|
||||||
process.env["INPUT_HIDE"] = "true"
|
process.env["INPUT_HIDE"] = "true"
|
||||||
expect(require("../src/config")).toMatchObject({
|
expect(require("../src/config")).toMatchObject({
|
||||||
|
baseUrl: "https://api.github.com",
|
||||||
pullRequestNumber: expect.any(Number),
|
pullRequestNumber: expect.any(Number),
|
||||||
repo: {owner: "marocchino", repo: "stick-pull-request-comment"},
|
repo: {owner: "marocchino", repo: "stick-pull-request-comment"},
|
||||||
header: "",
|
header: "",
|
||||||
|
|
@ -150,6 +176,7 @@ test("hideOldComment", async () => {
|
||||||
test("hideAndRecreate", async () => {
|
test("hideAndRecreate", async () => {
|
||||||
process.env["INPUT_HIDE_AND_RECREATE"] = "true"
|
process.env["INPUT_HIDE_AND_RECREATE"] = "true"
|
||||||
expect(require("../src/config")).toMatchObject({
|
expect(require("../src/config")).toMatchObject({
|
||||||
|
baseUrl: "https://api.github.com",
|
||||||
pullRequestNumber: expect.any(Number),
|
pullRequestNumber: expect.any(Number),
|
||||||
repo: {owner: "marocchino", repo: "stick-pull-request-comment"},
|
repo: {owner: "marocchino", repo: "stick-pull-request-comment"},
|
||||||
header: "",
|
header: "",
|
||||||
|
|
@ -168,6 +195,7 @@ test("hideAndRecreate", async () => {
|
||||||
test("hideClassify", async () => {
|
test("hideClassify", async () => {
|
||||||
process.env["INPUT_HIDE_CLASSIFY"] = "OFF_TOPIC"
|
process.env["INPUT_HIDE_CLASSIFY"] = "OFF_TOPIC"
|
||||||
expect(require("../src/config")).toMatchObject({
|
expect(require("../src/config")).toMatchObject({
|
||||||
|
baseUrl: "https://api.github.com",
|
||||||
pullRequestNumber: expect.any(Number),
|
pullRequestNumber: expect.any(Number),
|
||||||
repo: {owner: "marocchino", repo: "stick-pull-request-comment"},
|
repo: {owner: "marocchino", repo: "stick-pull-request-comment"},
|
||||||
header: "",
|
header: "",
|
||||||
|
|
@ -186,6 +214,7 @@ test("hideClassify", async () => {
|
||||||
test("hideDetails", async () => {
|
test("hideDetails", async () => {
|
||||||
process.env["INPUT_HIDE_DETAILS"] = "true"
|
process.env["INPUT_HIDE_DETAILS"] = "true"
|
||||||
expect(require("../src/config")).toMatchObject({
|
expect(require("../src/config")).toMatchObject({
|
||||||
|
baseUrl: "https://api.github.com",
|
||||||
pullRequestNumber: expect.any(Number),
|
pullRequestNumber: expect.any(Number),
|
||||||
repo: {owner: "marocchino", repo: "stick-pull-request-comment"},
|
repo: {owner: "marocchino", repo: "stick-pull-request-comment"},
|
||||||
header: "",
|
header: "",
|
||||||
|
|
@ -205,6 +234,7 @@ describe("path", () => {
|
||||||
test("when exists return content of a file", async () => {
|
test("when exists return content of a file", async () => {
|
||||||
process.env["INPUT_PATH"] = "./__tests__/assets/result"
|
process.env["INPUT_PATH"] = "./__tests__/assets/result"
|
||||||
expect(require("../src/config")).toMatchObject({
|
expect(require("../src/config")).toMatchObject({
|
||||||
|
baseUrl: "https://api.github.com",
|
||||||
pullRequestNumber: expect.any(Number),
|
pullRequestNumber: expect.any(Number),
|
||||||
repo: {owner: "marocchino", repo: "stick-pull-request-comment"},
|
repo: {owner: "marocchino", repo: "stick-pull-request-comment"},
|
||||||
header: "",
|
header: "",
|
||||||
|
|
@ -224,6 +254,7 @@ describe("path", () => {
|
||||||
test("glob match files", async () => {
|
test("glob match files", async () => {
|
||||||
process.env["INPUT_PATH"] = "./__tests__/assets/*"
|
process.env["INPUT_PATH"] = "./__tests__/assets/*"
|
||||||
expect(require("../src/config")).toMatchObject({
|
expect(require("../src/config")).toMatchObject({
|
||||||
|
baseUrl: "https://api.github.com",
|
||||||
pullRequestNumber: expect.any(Number),
|
pullRequestNumber: expect.any(Number),
|
||||||
repo: {owner: "marocchino", repo: "stick-pull-request-comment"},
|
repo: {owner: "marocchino", repo: "stick-pull-request-comment"},
|
||||||
header: "",
|
header: "",
|
||||||
|
|
@ -245,6 +276,7 @@ describe("path", () => {
|
||||||
test("when not exists return null string", async () => {
|
test("when not exists return null string", async () => {
|
||||||
process.env["INPUT_PATH"] = "./__tests__/assets/not_exists"
|
process.env["INPUT_PATH"] = "./__tests__/assets/not_exists"
|
||||||
expect(require("../src/config")).toMatchObject({
|
expect(require("../src/config")).toMatchObject({
|
||||||
|
baseUrl: "https://api.github.com",
|
||||||
pullRequestNumber: expect.any(Number),
|
pullRequestNumber: expect.any(Number),
|
||||||
repo: {owner: "marocchino", repo: "stick-pull-request-comment"},
|
repo: {owner: "marocchino", repo: "stick-pull-request-comment"},
|
||||||
header: "",
|
header: "",
|
||||||
|
|
@ -265,6 +297,7 @@ describe("path", () => {
|
||||||
test("message", async () => {
|
test("message", async () => {
|
||||||
process.env["INPUT_MESSAGE"] = "hello there"
|
process.env["INPUT_MESSAGE"] = "hello there"
|
||||||
expect(require("../src/config")).toMatchObject({
|
expect(require("../src/config")).toMatchObject({
|
||||||
|
baseUrl: "https://api.github.com",
|
||||||
pullRequestNumber: expect.any(Number),
|
pullRequestNumber: expect.any(Number),
|
||||||
repo: {owner: "marocchino", repo: "stick-pull-request-comment"},
|
repo: {owner: "marocchino", repo: "stick-pull-request-comment"},
|
||||||
header: "",
|
header: "",
|
||||||
|
|
@ -284,6 +317,7 @@ test("message", async () => {
|
||||||
test("ignore_empty", async () => {
|
test("ignore_empty", async () => {
|
||||||
process.env["INPUT_IGNORE_EMPTY"] = "true"
|
process.env["INPUT_IGNORE_EMPTY"] = "true"
|
||||||
expect(require("../src/config")).toMatchObject({
|
expect(require("../src/config")).toMatchObject({
|
||||||
|
baseUrl: "https://api.github.com",
|
||||||
pullRequestNumber: expect.any(Number),
|
pullRequestNumber: expect.any(Number),
|
||||||
repo: {owner: "marocchino", repo: "stick-pull-request-comment"},
|
repo: {owner: "marocchino", repo: "stick-pull-request-comment"},
|
||||||
header: "",
|
header: "",
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,10 @@ github-token:
|
||||||
pull-requests-reason: to create or update PR comment
|
pull-requests-reason: to create or update PR comment
|
||||||
|
|
||||||
inputs:
|
inputs:
|
||||||
|
base_url:
|
||||||
|
description: "base api url. default to: https://api.github.com"
|
||||||
|
default: "https://api.github.com"
|
||||||
|
required: false
|
||||||
header:
|
header:
|
||||||
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."
|
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."
|
||||||
default: ""
|
default: ""
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ export const pullRequestNumber =
|
||||||
context?.payload?.pull_request?.number ||
|
context?.payload?.pull_request?.number ||
|
||||||
+core.getInput("number", {required: false})
|
+core.getInput("number", {required: false})
|
||||||
|
|
||||||
|
export const baseUrl = core.getInput("base_url", {required: true})
|
||||||
export const repo = buildRepo()
|
export const repo = buildRepo()
|
||||||
export const header = core.getInput("header", {required: false})
|
export const header = core.getInput("header", {required: false})
|
||||||
export const append = core.getBooleanInput("append", {required: true})
|
export const append = core.getBooleanInput("append", {required: true})
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ import * as github from "@actions/github"
|
||||||
import {
|
import {
|
||||||
append,
|
append,
|
||||||
getBody,
|
getBody,
|
||||||
|
baseUrl,
|
||||||
deleteOldComment,
|
deleteOldComment,
|
||||||
githubToken,
|
githubToken,
|
||||||
header,
|
header,
|
||||||
|
|
@ -56,7 +57,7 @@ async function run(): Promise<undefined> {
|
||||||
throw new Error("hide and hide_and_recreate cannot be both set to true")
|
throw new Error("hide and hide_and_recreate cannot be both set to true")
|
||||||
}
|
}
|
||||||
|
|
||||||
const octokit = github.getOctokit(githubToken)
|
const octokit = github.getOctokit(githubToken, {baseUrl})
|
||||||
const previous = await findPreviousComment(
|
const previous = await findPreviousComment(
|
||||||
octokit,
|
octokit,
|
||||||
repo,
|
repo,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue