Skip to content

Commit 6545176

Browse files
authored
Arc 2643 audit log table entry (#2580)
1 parent f0aa195 commit 6545176

12 files changed

+476
-26
lines changed

Diff for: jest.config.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ module.exports = {
3333
},
3434
"collectCoverageFrom": [
3535
"src/**/*.{ts,tsx}",
36-
"!src/**/*.d.ts"
36+
"!src/**/*.d.ts",
37+
"!src/util/workers-health-monitor.ts"
3738
],
3839
"maxConcurrency": 1,
3940
"maxWorkers": 1,

Diff for: src/github/deployment.ts

+21-1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,17 @@ export const processDeployment = async (
5858
webhookReceived: webhookReceivedDate
5959
});
6060

61+
const subscription = await Subscription.getSingleInstallation(
62+
jiraHost,
63+
gitHubInstallationId,
64+
gitHubAppId
65+
);
66+
67+
if (!subscription) {
68+
logger.info("No subscription was found, stop processing the push");
69+
return;
70+
}
71+
6172
if (await isBlocked(jiraHost, gitHubInstallationId, logger)) {
6273
logger.warn("blocking processing of push message because installationId is on the blocklist");
6374
return;
@@ -89,7 +100,16 @@ export const processDeployment = async (
89100
return;
90101
}
91102

92-
const result: DeploymentsResult = await jiraClient.deployment.submit(jiraPayload, webhookPayload.repository.id);
103+
const result: DeploymentsResult = await jiraClient.deployment.submit(
104+
jiraPayload,
105+
webhookPayload.repository.id,
106+
{
107+
preventTransitions: false,
108+
operationType: "NORMAL",
109+
auditLogsource: "WEBHOOK",
110+
subscriptionId: subscription.id
111+
}
112+
);
93113

94114
// TODO - remove the rate limited test once valid metrics have been decided
95115
!rateLimited && emitWebhookProcessedMetrics(

Diff for: src/interfaces/jira.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { TransformedRepositoryId } from "~/src/transforms/transform-repository-id";
2-
import { AuditLogSourceType, AuditEntityType } from "../services/audit-log-service";
2+
import { AuditLogSourceType } from "../services/audit-log-service";
33

44
interface JiraPullRequestCommit {
55
id: string;
@@ -254,6 +254,6 @@ export interface JiraSubmitOptions {
254254
preventTransitions: boolean;
255255
operationType: JiraOperationType;
256256
auditLogsource: AuditLogSourceType;
257-
entityAction: AuditEntityType;
257+
entityAction?: string;
258258
subscriptionId: number;
259259
}

Diff for: src/jira/client/jira-client-audit-log-helper.test.ts

+284-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { processBatchedBulkUpdateResp, processWorkflowSubmitResp } from "./jira-client-audit-log-helper";
1+
import { processBatchedBulkUpdateResp, processWorkflowSubmitResp, processDeploySubmitResp } from "./jira-client-audit-log-helper";
22
import { getLogger } from "config/logger";
33
import { JiraSubmitOptions } from "interfaces/jira";
44

@@ -647,3 +647,286 @@ describe("processWorkflowSubmitResp", () => {
647647
});
648648
});
649649
});
650+
651+
describe("processDeploySubmitResp", () => {
652+
const mockLogger = getLogger("mock-logger");
653+
it("should return isSuccess as false when status code is anything other than 202", () => {
654+
const reqDeploymentDataArray = [
655+
{
656+
schemaVersion: "1.0",
657+
deploymentSequenceNumber: 1194529862,
658+
updateSequenceNumber: 2835516764,
659+
displayName: "Update manifest.json KAM-6",
660+
url: "https://github.com/KamaksheeSamant/react-cods-hub/actions/runs/7014571070/job/19082502671",
661+
description: "deploy",
662+
lastUpdated: "2023-11-28T05:22:38.000Z",
663+
state: "successful",
664+
pipeline: {
665+
id: "deploy",
666+
displayName: "deploy",
667+
url: "https://github.com/KamaksheeSamant/react-cods-hub/actions/runs/7014571070/job/19082502671"
668+
},
669+
environment: {
670+
id: "github-pages",
671+
displayName: "github-pages",
672+
type: "unmapped"
673+
},
674+
associations: [
675+
{ associationType: "issueIdOrKeys", values: ["KAM-6"] },
676+
{
677+
associationType: "commit",
678+
values: [
679+
{
680+
commitHash: "f4bc81f3ddb980ac34e4ae9acef108e34840567f",
681+
repositoryId: "691330555"
682+
}
683+
]
684+
}
685+
]
686+
}
687+
];
688+
const response = {
689+
status: 400,
690+
data: {
691+
unknownIssueKeys: [],
692+
acceptedDeployments: [],
693+
rejectedDeployments: []
694+
}
695+
};
696+
const options: JiraSubmitOptions = { preventTransitions:false, operationType: "NORMAL", auditLogsource: "WEBHOOK", subscriptionId: 1122334455 };
697+
698+
const result = processDeploySubmitResp({
699+
reqDeploymentDataArray,
700+
response,
701+
options,
702+
logger: mockLogger
703+
});
704+
705+
expect(result).toEqual({
706+
isSuccess: false
707+
});
708+
});
709+
it("should return isSuccess as false when status code is 202 but there is no acceptedDeployments", () => {
710+
const reqDeploymentDataArray = [
711+
{
712+
schemaVersion: "1.0",
713+
deploymentSequenceNumber: 1194529862,
714+
updateSequenceNumber: 2835516764,
715+
displayName: "Update manifest.json KAM-6",
716+
url: "https://github.com/KamaksheeSamant/react-cods-hub/actions/runs/7014571070/job/19082502671",
717+
description: "deploy",
718+
lastUpdated: "2023-11-28T05:22:38.000Z",
719+
state: "successful",
720+
pipeline: {
721+
id: "deploy",
722+
displayName: "deploy",
723+
url: "https://github.com/KamaksheeSamant/react-cods-hub/actions/runs/7014571070/job/19082502671"
724+
},
725+
environment: {
726+
id: "github-pages",
727+
displayName: "github-pages",
728+
type: "unmapped"
729+
},
730+
associations: [
731+
{ associationType: "issueIdOrKeys", values: ["KAM-6"] },
732+
{
733+
associationType: "commit",
734+
values: [
735+
{
736+
commitHash: "f4bc81f3ddb980ac34e4ae9acef108e34840567f",
737+
repositoryId: "691330555"
738+
}
739+
]
740+
}
741+
]
742+
}
743+
];
744+
const response = {
745+
status: 202,
746+
data: {
747+
unknownIssueKeys: [],
748+
acceptedDeployments: [],
749+
rejectedDeployments: []
750+
}
751+
};
752+
const options: JiraSubmitOptions = { preventTransitions:false, operationType: "NORMAL", auditLogsource: "WEBHOOK", subscriptionId: 1122334455 };
753+
754+
const result = processDeploySubmitResp({
755+
reqDeploymentDataArray,
756+
response,
757+
options,
758+
logger: mockLogger
759+
});
760+
761+
expect(result).toEqual({
762+
isSuccess: false
763+
});
764+
});
765+
it("should return isSuccess as true when status code is 202 and there are/is acceptedDeployments but the result has rejectedDeployments as well", () => {
766+
const reqDeploymentDataArray = [
767+
{
768+
schemaVersion: "1.0",
769+
deploymentSequenceNumber: 1194529862,
770+
updateSequenceNumber: 2835516764,
771+
displayName: "Update manifest.json KAM-6",
772+
url: "https://github.com/KamaksheeSamant/react-cods-hub/actions/runs/7014571070/job/19082502671",
773+
description: "deploy",
774+
lastUpdated: "2023-11-28T05:22:38.000Z",
775+
state: "successful",
776+
pipeline: {
777+
id: "deploy",
778+
displayName: "deploy",
779+
url: "https://github.com/KamaksheeSamant/react-cods-hub/actions/runs/7014571070/job/19082502671"
780+
},
781+
environment: {
782+
id: "github-pages",
783+
displayName: "github-pages",
784+
type: "unmapped"
785+
},
786+
associations: [
787+
{ associationType: "issueIdOrKeys", values: ["KAM-6"] },
788+
{
789+
associationType: "commit",
790+
values: [
791+
{
792+
commitHash: "f4bc81f3ddb980ac34e4ae9acef108e34840567f",
793+
repositoryId: "691330555"
794+
}
795+
]
796+
}
797+
]
798+
}
799+
];
800+
const response = {
801+
status: 202,
802+
data: {
803+
unknownIssueKeys: [],
804+
acceptedDeployments: [
805+
{
806+
pipelineId: "deploy",
807+
environmentId: "github-pages",
808+
deploymentSequenceNumber: 1194529862
809+
}
810+
],
811+
rejectedDeployments: [
812+
{
813+
pipelineId: "deploy",
814+
environmentId: "github-pages",
815+
deploymentSequenceNumber: 1188282781
816+
}
817+
]
818+
}
819+
};
820+
const options: JiraSubmitOptions = { preventTransitions:false, operationType: "NORMAL", auditLogsource: "WEBHOOK", subscriptionId: 1122334455 };
821+
822+
const result = processDeploySubmitResp({
823+
reqDeploymentDataArray,
824+
response,
825+
options,
826+
logger: mockLogger
827+
});
828+
829+
expect(result).toEqual({
830+
isSuccess: true,
831+
auditInfo: [
832+
{
833+
createdAt: expect.anything(),
834+
entityAction: "successful",
835+
entityId: "1194529862",
836+
entityType: "deployments",
837+
issueKey: "KAM-6",
838+
source: "WEBHOOK",
839+
subscriptionId: 1122334455
840+
}
841+
]
842+
});
843+
});
844+
it("should extract the build with 2 issue keys linked - audit info for logging", () => {
845+
const reqDeploymentDataArray = [
846+
{
847+
schemaVersion: "1.0",
848+
deploymentSequenceNumber: 1194529862,
849+
updateSequenceNumber: 2835516764,
850+
displayName: "Update manifest.json KAM-6",
851+
url: "https://github.com/KamaksheeSamant/react-cods-hub/actions/runs/7014571070/job/19082502671",
852+
description: "deploy",
853+
lastUpdated: "2023-11-28T05:22:38.000Z",
854+
state: "successful",
855+
pipeline: {
856+
id: "deploy",
857+
displayName: "deploy",
858+
url: "https://github.com/KamaksheeSamant/react-cods-hub/actions/runs/7014571070/job/19082502671"
859+
},
860+
environment: {
861+
id: "github-pages",
862+
displayName: "github-pages",
863+
type: "unmapped"
864+
},
865+
associations: [
866+
{ associationType: "issueIdOrKeys", values: ["KAM-6", "KAM-5"] },
867+
{
868+
associationType: "commit",
869+
values: [
870+
{
871+
commitHash: "f4bc81f3ddb980ac34e4ae9acef108e34840567f",
872+
repositoryId: "691330555"
873+
}
874+
]
875+
}
876+
]
877+
}
878+
];
879+
const response = {
880+
status: 202,
881+
data: {
882+
unknownIssueKeys: [],
883+
acceptedDeployments: [
884+
{
885+
pipelineId: "deploy",
886+
environmentId: "github-pages",
887+
deploymentSequenceNumber: 1194529862
888+
}
889+
],
890+
rejectedDeployments: [
891+
{
892+
pipelineId: "deploy",
893+
environmentId: "github-pages",
894+
deploymentSequenceNumber: 1188282781
895+
}
896+
]
897+
}
898+
};
899+
const options: JiraSubmitOptions = { preventTransitions:false, operationType: "NORMAL", auditLogsource: "WEBHOOK", subscriptionId: 1122334455 };
900+
901+
const result = processDeploySubmitResp({
902+
reqDeploymentDataArray,
903+
response,
904+
options,
905+
logger: mockLogger
906+
});
907+
908+
expect(result).toEqual({
909+
isSuccess: true,
910+
auditInfo: [
911+
{
912+
createdAt: expect.anything(),
913+
entityAction: "successful",
914+
entityId: "1194529862",
915+
entityType: "deployments",
916+
issueKey: "KAM-6",
917+
source: "WEBHOOK",
918+
subscriptionId: 1122334455
919+
},
920+
{
921+
createdAt: expect.anything(),
922+
entityAction: "successful",
923+
entityId: "1194529862",
924+
entityType: "deployments",
925+
issueKey: "KAM-5",
926+
source: "WEBHOOK",
927+
subscriptionId: 1122334455
928+
}
929+
]
930+
});
931+
});
932+
});

0 commit comments

Comments
 (0)