Skip to content

Commit 51b1423

Browse files
Copilotpelikhan
andauthored
Add fork context warning to validate_secrets.cjs (#18523)
* Initial plan * Add fork context warning to validate_secrets.cjs (#18534) Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
1 parent 9d21367 commit 51b1423

2 files changed

Lines changed: 45 additions & 1 deletion

File tree

actions/setup/js/validate_secrets.cjs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,15 @@ async function testNotionAPI(token) {
475475
}
476476
}
477477

478+
/**
479+
* Check if running in a forked repository
480+
* @param {Object|null|undefined} payload - GitHub context payload
481+
* @returns {boolean}
482+
*/
483+
function isForkRepository(payload) {
484+
return payload?.repository?.fork === true;
485+
}
486+
478487
/**
479488
* Format status emoji
480489
* @param {string} status
@@ -615,6 +624,10 @@ async function main() {
615624
try {
616625
core.info("Starting secret validation...");
617626

627+
if (isForkRepository(context.payload)) {
628+
core.warning(`⚠️ This repository is a fork. Secrets from the parent repository are not inherited. You must configure each secret listed below directly in your fork's repository settings.`);
629+
}
630+
618631
const owner = context.repo.owner;
619632
const repo = context.repo.repo;
620633

@@ -749,6 +762,7 @@ async function main() {
749762

750763
module.exports = {
751764
main,
765+
isForkRepository,
752766
testGitHubRESTAPI,
753767
testGitHubGraphQLAPI,
754768
testCopilotCLI,

actions/setup/js/validate_secrets.test.cjs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// @ts-check
22

33
import { describe, it, expect } from "vitest";
4-
import { testGitHubRESTAPI, testGitHubGraphQLAPI, testCopilotCLI, testAnthropicAPI, testOpenAIAPI, testBraveSearchAPI, testNotionAPI, generateMarkdownReport } from "./validate_secrets.cjs";
4+
import { testGitHubRESTAPI, testGitHubGraphQLAPI, testCopilotCLI, testAnthropicAPI, testOpenAIAPI, testBraveSearchAPI, testNotionAPI, generateMarkdownReport, isForkRepository } from "./validate_secrets.cjs";
55

66
describe("validate_secrets", () => {
77
describe("testGitHubRESTAPI", () => {
@@ -211,4 +211,34 @@ describe("validate_secrets", () => {
211211
expect(report).toContain("GitHub GraphQL API");
212212
});
213213
});
214+
215+
describe("isForkRepository", () => {
216+
it("should return true when repository.fork is true", () => {
217+
const payload = { repository: { fork: true } };
218+
expect(isForkRepository(payload)).toBe(true);
219+
});
220+
221+
it("should return false when repository.fork is false", () => {
222+
const payload = { repository: { fork: false } };
223+
expect(isForkRepository(payload)).toBe(false);
224+
});
225+
226+
it("should return false when repository.fork is absent", () => {
227+
const payload = { repository: {} };
228+
expect(isForkRepository(payload)).toBe(false);
229+
});
230+
231+
it("should return false when repository is absent", () => {
232+
const payload = {};
233+
expect(isForkRepository(payload)).toBe(false);
234+
});
235+
236+
it("should return false when payload is null", () => {
237+
expect(isForkRepository(null)).toBe(false);
238+
});
239+
240+
it("should return false when payload is undefined", () => {
241+
expect(isForkRepository(undefined)).toBe(false);
242+
});
243+
});
214244
});

0 commit comments

Comments
 (0)