Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 4 additions & 14 deletions activity-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`;
}

/**
Expand Down
56 changes: 50 additions & 6 deletions activity-script.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down Expand Up @@ -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",
Expand Down
4 changes: 1 addition & 3 deletions types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,7 @@ export type UpsunValidatedVariables = UpsunVariables & {
};

export interface UpsunProject {
subscription: {
subscription_management_uri?: string;
};
organization: string | null;
}

export interface UpsunContext {
Expand Down
Loading