diff --git a/activity-script.js b/activity-script.js index e36fa55..4f84e53 100644 --- a/activity-script.js +++ b/activity-script.js @@ -460,23 +460,13 @@ function getEnvironmentUrl(activity) { * @return {string|undefined} */ function getLogUrl(context) { - // The owner slug is not directly available in any of the provided properties - // so we have to extract it. - // Separate the first part of the path which contains the slug. - const subscriptionManagementUri = - context.project.subscription.subscription_management_uri; - const matches = subscriptionManagementUri?.match(/\.com\/([^/]+)/); - - if (!matches?.[1]) { - console.log( - "Unable to determine Upsun owner organization from subscription_management_uri", - subscriptionManagementUri, - ); + const organizationId = context.project.organization; + if (!organizationId) { + console.log("Unable to determine Upsun organization for log url"); return undefined; } - const ownerSlug = matches[1]; - return `https://console.upsun.com/${ownerSlug}/${context.activity.project}/-/log/${context.activity.id}`; + return `https://console.upsun.com/${organizationId}/${context.activity.project}/-/log/${context.activity.id}`; } /** diff --git a/activity-script.test.js b/activity-script.test.js index f89d2bd..c906fd3 100644 --- a/activity-script.test.js +++ b/activity-script.test.js @@ -271,12 +271,7 @@ function createPushActivity({ type = "environment.push", ...options }) { function runScript({ activity, variables = defaultVariables, - project = { - subscription: { - subscription_management_uri: - "https://accounts.upsun.com/my-org/subscriptions/abc", - }, - }, + project = { organization: "org-for-default-project" }, latestDeploymentStatus = 200, deploymentByIdStatus = 200, deployments = [ @@ -661,6 +656,55 @@ test("environment.push (complete) marks mapped deployment as success", () => { assert.equal(createStatusCall.body.auto_inactive, true); }); +test("deployment status links to the activity log in the project organization", () => { + const storage = createStorage({ + "upsun-github-deployment-by-activity:act-log": "781", + }); + const activity = createActivity({ + id: "act-log", + type: "environment.push", + state: "complete", + result: "success", + }); + const calls = runScript({ + activity, + project: { organization: "org-with-log" }, + storage, + deployments: [createGitHubDeployment(781, "main")], + }); + const createStatusCall = calls.find((call) => { + return call.method === "POST" && /\/statuses$/.test(call.url); + }); + assert.ok(createStatusCall?.body); + assert.equal( + createStatusCall.body.log_url, + `https://console.upsun.com/org-with-log/${activity.project}/-/log/act-log`, + ); +}); + +test("deployment status omits log url when project has no organization", () => { + const storage = createStorage({ + "upsun-github-deployment-by-activity:act-no-org": "782", + }); + const activity = createActivity({ + id: "act-no-org", + type: "environment.push", + state: "complete", + result: "success", + }); + const calls = runScript({ + activity, + project: { organization: null }, + storage, + deployments: [createGitHubDeployment(782, "main")], + }); + const createStatusCall = calls.find((call) => { + return call.method === "POST" && /\/statuses$/.test(call.url); + }); + assert.ok(createStatusCall?.body); + assert.equal("log_url" in createStatusCall.body, false); +}); + test("environment.push (complete failure) marks mapped deployment as failure", () => { const storage = createStorage({ "upsun-github-deployment-by-activity:act-5b": "779", diff --git a/types.d.ts b/types.d.ts index 897c1c0..ff79ccf 100644 --- a/types.d.ts +++ b/types.d.ts @@ -75,9 +75,7 @@ export type UpsunValidatedVariables = UpsunVariables & { }; export interface UpsunProject { - subscription: { - subscription_management_uri?: string; - }; + organization: string | null; } export interface UpsunContext {