@@ -29016,6 +29016,7 @@ const Confluence = __nccwpck_require__(3099);
2901629016const core = __nccwpck_require__(2186);
2901729017const parser = __nccwpck_require__(4363)
2901829018const path = __nccwpck_require__(1017)
29019+ const fs = __nccwpck_require__(7147)
2901929020const axios = __nccwpck_require__(8757)
2902029021
2902129022const filesStructure = __nccwpck_require__(8612);
@@ -29086,19 +29087,48 @@ async function handleAttachments(contentPageId, data) {
2908629087}
2908729088
2908829089async function validateSubscription() {
29089- const API_URL = `https://agent.api.stepsecurity.io/v1/github/${process.env.GITHUB_REPOSITORY}/actions/subscription`;
29090-
29090+ let repoPrivate;
29091+ const eventPath = process.env.GITHUB_EVENT_PATH;
29092+ if (eventPath && fs.existsSync(eventPath)) {
29093+ const payload = JSON.parse(fs.readFileSync(eventPath, "utf8"));
29094+ repoPrivate = payload?.repository?.private;
29095+ }
29096+
29097+ const upstream = "Bhacaz/docs-as-code-confluence";
29098+ const action = process.env.GITHUB_ACTION_REPOSITORY;
29099+ const docsUrl =
29100+ "https://docs.stepsecurity.io/actions/stepsecurity-maintained-actions";
29101+
29102+ core.info("");
29103+ core.info("[1;36mStepSecurity Maintained Action[0m");
29104+ core.info(`Secure drop-in replacement for ${upstream}`);
29105+ if (repoPrivate === false)
29106+ core.info("[32m✓ Free for public repositories[0m");
29107+ core.info(`[36mLearn more:[0m ${docsUrl}`);
29108+ core.info("");
29109+
29110+ if (repoPrivate === false) return;
29111+ const serverUrl = process.env.GITHUB_SERVER_URL || "https://github.com";
29112+ const body = { action: action || "" };
29113+
29114+ if (serverUrl !== "https://github.com") body.ghes_server = serverUrl;
2909129115 try {
29092- await axios.get(API_URL, {timeout: 3000});
29116+ await axios.post(
29117+ `https://agent.api.stepsecurity.io/v1/github/${process.env.GITHUB_REPOSITORY}/actions/maintained-actions-subscription`,
29118+ body,
29119+ { timeout: 3000 },
29120+ );
2909329121 } catch (error) {
29094- if (error.response && error.response.status === 403) {
29095- console.error(
29096- 'Subscription is not valid. Reach out to
[email protected] '
29122+ if (axios.isAxiosError(error) && error.response?.status === 403) {
29123+ core.error(
29124+ `[1;31mThis action requires a StepSecurity subscription for private repositories.[0m`,
29125+ );
29126+ core.error(
29127+ `[31mLearn how to enable a subscription: ${docsUrl}[0m`,
2909729128 );
2909829129 process.exit(1);
29099- } else {
29100- core.info('Timeout or API not reachable. Continuing to next step.');
2910129130 }
29131+ core.info("Timeout or API not reachable. Continuing to next step.");
2910229132 }
2910329133}
2910429134
0 commit comments