Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support affected integrations #15

Merged
merged 3 commits into from
Jan 31, 2024
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
30 changes: 16 additions & 14 deletions .github/workflows/syschange.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,19 @@ jobs:
main:
runs-on: ubuntu-latest
steps:
- name: Create Informational Syschange
id: syschange
uses: brownuniversity/create-informational-syschange@main
with:
summary: "Test Ticket"
description: "Testing Create Pull Request Github Action"
author: ${{ github.event.sender.login }}
group: "OIT-JSM-Web Services"
affectedServices: 1631557
apiKey: ${{ secrets.WS_ATLASSIAN_KEY }}
- name: Print Ticket Link
run: |
echo '::echo::on'
echo "${{ steps.syschange.outputs.ticket-link }}"
- uses: actions/checkout@v4
- name: Create Informational Syschange
id: syschange
uses: ./
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This lets us test with the version of the action from the branch used for testing.

with:
summary: "Test Ticket"
description: "Testing Create Pull Request Github Action"
author: ${{ github.event.sender.login }}
group: "OIT-JSM-Web Services"
affectedServices: 1631557
affectedIntegrations: 2344418
apiKey: ${{ secrets.WS_ATLASSIAN_KEY }}
- name: Print Ticket Link
run: |
echo '::echo::on'
echo "${{ steps.syschange.outputs.ticket-link }}"
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ See [syschange.yaml](.github/workflows/syschange.yaml) for an example, and use t

- `description`: Longer description of change
- `installer`: Installer Atlassian ID (defaults to EAS service account)
- `affectedIntegrations`: Comma-separated Atlassian IDs of the affected integrations (see below)

### Outputs

Expand All @@ -37,3 +38,9 @@ To find the Atlassian ID of an affected service (we'll use ASK as an example):
1. Navigate to the JSM application object collection: https://brown.atlassian.net/jira/servicedesk/assets/object-schema/3?typeId=25
2. Locate your service: https://brown.atlassian.net/jira/servicedesk/assets/object-schema/3?typeId=25&objectId=509576
3. Grab the `objectId` from URL: `509576`

To find the Atlassian ID of an affected integration (we'll use banner-sapi as an example):

1. Navigate to the JSM application object collection: https://brown.atlassian.net/jira/servicedesk/assets/object-schema/14?typeId=215
2. Locate your integration: https://brown.atlassian.net/jira/servicedesk/assets/object-schema/14?typeId=215&objectId=2344418
3. Grab the `objectId` from URL: `2344418`
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ inputs:
description: "Syschange installer Atlassian ID"
required: false
default: '712020:db823f4a-761e-42b7-aff2-bcd0a391c480'
affectedIntegrations:
description: 'Comma-separated list of Atlassian IDs for the affected integrations'
required: false
outputs:
ticket-link:
description: 'URL of created Informational Syschange'
Expand Down
10 changes: 10 additions & 0 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2779,6 +2779,7 @@ const customFields = {
REQUEST_TYPE: "customfield_10010",
RESPONSIBLE_GROUP: "customfield_10058",
AFFECTED_SERVICES: "customfield_10171",
AFFECTED_INTEGRATIONS: "customfield_10406",
GITHUB_ID: "customfield_10392",
PLANNED_START: "customfield_10107",
PLANNED_END: "customfield_10049",
Expand All @@ -2790,13 +2791,18 @@ async function run() {
author: core.getInput("author", { required: true }),
group: core.getInput("group", { required: true }),
affectedServices: core.getInput("affectedServices", { required: true }),
affectedIntegrations: core.getInput("affectedIntegrations") || "",
apiKey: core.getInput("apiKey", { required: true }),
description: core.getInput("description") || "",
installer: core.getInput("installer") || jsmConstants.DEFAULT_INSTALLER,
};
const affectedServicesJson = inputs.affectedServices
.split(",")
.map((id) => ({ id: `${jsmConstants.WORKSPACE_ID}:${id}` }));
const affectedIntegrationsJson = inputs.affectedIntegrations
.split(",")
.filter((x) => x)
.map((id) => ({ id: `${jsmConstants.WORKSPACE_ID}:${id}` }));
const now = new Date().toISOString().replace(/\.\d+/, "");
const data = {
fields: {
Expand All @@ -2813,6 +2819,10 @@ async function run() {
[customFields.PLANNED_END]: now,
},
};
if (affectedIntegrationsJson.length > 0) {
data.fields[customFields.AFFECTED_INTEGRATIONS] =
affectedIntegrationsJson;
}
const headers = {
authorization: `Basic ${Buffer.from(inputs.apiKey).toString("base64")}`,
};
Expand Down
99 changes: 99 additions & 0 deletions src/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ describe("with default inputs", () => {
author: "oit-eas-blackhole",
group: "OIT-JSM-EAS",
affectedServices: "12345",
affectedIntegrations: "6789",
apiKey: "username:password",
});
const scope = nock("https://brown.atlassian.net", {
Expand All @@ -58,6 +59,9 @@ describe("with default inputs", () => {
customfield_10171: [
{ id: "3015eb17-fcd8-4eb8-b534-dfbce48cd828:12345" },
],
customfield_10406: [
{ id: "3015eb17-fcd8-4eb8-b534-dfbce48cd828:6789" },
],
customfield_10392: "oit-eas-blackhole",
customfield_10107: /\d\d\d\d-\d\d-\d\dT\d\d:\d\d:\d\dZ/,
customfield_10049: /\d\d\d\d-\d\d-\d\dT\d\d:\d\d:\d\dZ/,
Expand All @@ -82,6 +86,7 @@ describe("with optional inputs", () => {
author: "oit-eas-blackhole",
group: "OIT-JSM-EAS",
affectedServices: "12345",
affectedIntegrations: "6789",
apiKey: "username:password",
description: "Released v1.0.1 of Generic",
installer: "test-installer-id",
Expand All @@ -101,6 +106,9 @@ describe("with optional inputs", () => {
customfield_10171: [
{ id: "3015eb17-fcd8-4eb8-b534-dfbce48cd828:12345" },
],
customfield_10406: [
{ id: "3015eb17-fcd8-4eb8-b534-dfbce48cd828:6789" },
],
customfield_10392: "oit-eas-blackhole",
customfield_10107: /\d\d\d\d-\d\d-\d\dT\d\d:\d\d:\d\dZ/,
customfield_10049: /\d\d\d\d-\d\d-\d\dT\d\d:\d\d:\d\dZ/,
Expand All @@ -125,6 +133,7 @@ describe("affected services", () => {
author: "oit-eas-blackhole",
group: "OIT-JSM-EAS",
affectedServices: "12345",
affectedIntegrations: "6789",
apiKey: "username:password",
});
const scope = nock("https://brown.atlassian.net", {
Expand Down Expand Up @@ -153,6 +162,7 @@ describe("affected services", () => {
author: "oit-eas-blackhole",
group: "OIT-JSM-EAS",
affectedServices: "12345,67890,46873",
affectedIntegrations: "6789",
apiKey: "username:password",
});
const scope = nock("https://brown.atlassian.net", {
Expand All @@ -178,12 +188,101 @@ describe("affected services", () => {
});
});

describe("affected integrations", () => {
it("can be single-valued", async () => {
setInputs({
summary: "Generic v1.0.1",
author: "oit-eas-blackhole",
group: "OIT-JSM-EAS",
affectedServices: "12345",
affectedIntegrations: "6789",
apiKey: "username:password",
});
const scope = nock("https://brown.atlassian.net", {
reqheaders: expectedHeaders,
})
.post("/rest/api/2/issue", (body) => {
expect(body.fields.customfield_10406).toEqual([
{ id: "3015eb17-fcd8-4eb8-b534-dfbce48cd828:6789" },
]);
return true;
})
.reply(200, { key: "1234" });

await run();
expect(core.setOutput).toHaveBeenCalledTimes(1);
expect(core.setOutput).toHaveBeenCalledWith(
"ticket-link",
"https://brown.atlassian.net/browse/1234",
);
expect(scope.isDone()).toBe(true);
});

it("can be multi-valued", async () => {
setInputs({
summary: "Generic v1.0.1",
author: "oit-eas-blackhole",
group: "OIT-JSM-EAS",
affectedServices: "12345",
affectedIntegrations: "6789,67890,46873",
apiKey: "username:password",
});
const scope = nock("https://brown.atlassian.net", {
reqheaders: expectedHeaders,
})
.post("/rest/api/2/issue", (body) => {
expect(body.fields.customfield_10406).toEqual([
{ id: "3015eb17-fcd8-4eb8-b534-dfbce48cd828:6789" },
{ id: "3015eb17-fcd8-4eb8-b534-dfbce48cd828:67890" },
{ id: "3015eb17-fcd8-4eb8-b534-dfbce48cd828:46873" },
]);
return true;
})
.reply(200, { key: "1234" });

await run();
expect(core.setOutput).toHaveBeenCalledTimes(1);
expect(core.setOutput).toHaveBeenCalledWith(
"ticket-link",
"https://brown.atlassian.net/browse/1234",
);
expect(scope.isDone()).toBe(true);
});

it("can be empty", async () => {
setInputs({
summary: "Generic v1.0.1",
author: "oit-eas-blackhole",
group: "OIT-JSM-EAS",
affectedServices: "12345",
apiKey: "username:password",
});
const scope = nock("https://brown.atlassian.net", {
reqheaders: expectedHeaders,
})
.post("/rest/api/2/issue", (body) => {
expect(Object.keys(body.fields)).not.toContain("customfield_10406");
return true;
})
.reply(200, { key: "1234" });

await run();
expect(core.setOutput).toHaveBeenCalledTimes(1);
expect(core.setOutput).toHaveBeenCalledWith(
"ticket-link",
"https://brown.atlassian.net/browse/1234",
);
expect(scope.isDone()).toBe(true);
});
});

it("handles errors", async () => {
setInputs({
summary: "Generic v1.0.1",
author: "oit-eas-blackhole",
group: "OIT-JSM-EAS",
affectedServices: "12345,67890,46873",
affectedIntegrations: "6789",
apiKey: "username:password",
});
const scope = nock("https://brown.atlassian.net", {
Expand Down
10 changes: 10 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const customFields = {
REQUEST_TYPE: "customfield_10010",
RESPONSIBLE_GROUP: "customfield_10058",
AFFECTED_SERVICES: "customfield_10171",
AFFECTED_INTEGRATIONS: "customfield_10406",
GITHUB_ID: "customfield_10392",
PLANNED_START: "customfield_10107",
PLANNED_END: "customfield_10049",
Expand All @@ -24,13 +25,18 @@ export default async function run(): Promise<void> {
author: core.getInput("author", { required: true }),
group: core.getInput("group", { required: true }),
affectedServices: core.getInput("affectedServices", { required: true }),
affectedIntegrations: core.getInput("affectedIntegrations") || "",
apiKey: core.getInput("apiKey", { required: true }),
description: core.getInput("description") || "",
installer: core.getInput("installer") || jsmConstants.DEFAULT_INSTALLER,
};
const affectedServicesJson = inputs.affectedServices
.split(",")
.map((id) => ({ id: `${jsmConstants.WORKSPACE_ID}:${id}` }));
const affectedIntegrationsJson = inputs.affectedIntegrations
.split(",")
.filter((x) => x)
.map((id) => ({ id: `${jsmConstants.WORKSPACE_ID}:${id}` }));
const now = new Date().toISOString().replace(/\.\d+/, "");
const data = {
fields: {
Expand All @@ -47,6 +53,10 @@ export default async function run(): Promise<void> {
[customFields.PLANNED_END]: now,
},
};
if (affectedIntegrationsJson.length > 0) {
data.fields[customFields.AFFECTED_INTEGRATIONS] =
affectedIntegrationsJson;
}
const headers = {
authorization: `Basic ${Buffer.from(inputs.apiKey).toString("base64")}`,
};
Expand Down