Skip to content

Commit

Permalink
ARC-2604 remove ff for deployment webhook and backfill (#2540)
Browse files Browse the repository at this point in the history
  • Loading branch information
gxueatlassian authored Nov 9, 2023
1 parent 991215e commit e1b3e5b
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 287 deletions.
2 changes: 0 additions & 2 deletions src/config/feature-flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ export enum BooleanFlags {
VERBOSE_LOGGING = "verbose-logging",
SEND_PR_COMMENTS_TO_JIRA = "send-pr-comments-to-jira_zy5ib",
JIRA_ADMIN_CHECK = "jira-admin-check",
USE_DYNAMODB_FOR_DEPLOYMENT_WEBHOOK = "use-dynamodb-for-deployment-webhook",
USE_DYNAMODB_FOR_DEPLOYMENT_BACKFILL = "use-dynamodb-for-deployment-backfill",
LOG_CURLV_OUTPUT = "log-curlv-output",
ENABLE_SUBSCRIPTION_DEFERRED_INSTALL = "enable-subscription-deferred-install",
USE_REST_API_FOR_DISCOVERY = "use-rest-api-for-discovery-again",
Expand Down
8 changes: 2 additions & 6 deletions src/github/client/github-installation-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import {
GetRepositoriesResponse,
ViewerRepositoryCountQuery,
getDeploymentsResponse,
getDeploymentsQuery,
getDeploymentsQueryWithStatuses,
SearchedRepositoriesResponse,
getPullRequests,
Expand Down Expand Up @@ -462,12 +461,9 @@ export class GitHubInstallationClient extends GitHubClient {
return response?.data?.data;
}

public async getDeploymentsPage(jiraHost: string, owner: string, repoName: string, perPage?: number, cursor?: string | number): Promise<getDeploymentsResponse> {
public async getDeploymentsPage(owner: string, repoName: string, perPage?: number, cursor?: string | number): Promise<getDeploymentsResponse> {

const useDyanmoForBackfill = await booleanFlag(BooleanFlags.USE_DYNAMODB_FOR_DEPLOYMENT_BACKFILL, jiraHost);
const graphQuery = useDyanmoForBackfill ? getDeploymentsQueryWithStatuses : getDeploymentsQuery;

const response = await this.graphql<getDeploymentsResponse>(graphQuery,
const response = await this.graphql<getDeploymentsResponse>(getDeploymentsQueryWithStatuses,
await this.installationAuthenticationHeaders(),
{
owner,
Expand Down
38 changes: 0 additions & 38 deletions src/github/client/github-queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -573,44 +573,6 @@ export type getDeploymentsResponse = {
}
};

export const getDeploymentsQuery = `query ($owner: String!, $repo: String!, $per_page: Int!, $cursor: String) {
repository(owner: $owner, name: $repo){
deployments(first: $per_page, after: $cursor, orderBy: { direction: DESC, field: CREATED_AT }) {
edges {
cursor
node {
createdAt
repository {
id: databaseId
node_id: id
name
owner {
login
}
}
databaseId
commitOid
task
ref {
name
id
}
environment
description
latestStatus {
environmentUrl
logUrl
state
id
createdAt
updatedAt
}
}
}
}
}
}`;

export const getDeploymentsQueryWithStatuses = `query ($owner: String!, $repo: String!, $per_page: Int!, $cursor: String) {
repository(owner: $owner, name: $repo){
deployments(first: $per_page, after: $cursor, orderBy: { direction: DESC, field: CREATED_AT }) {
Expand Down
3 changes: 0 additions & 3 deletions src/github/deployment.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import { sqsQueues } from "../sqs/queues";
import { GITHUB_CLOUD_API_BASEURL, GITHUB_CLOUD_BASEURL } from "~/src/github/client/github-client-constants";
import { Subscription } from "models/subscription";
import deployment_status from "fixtures/deployment_status-basic.json";
import { booleanFlag, BooleanFlags } from "config/feature-flags";
import { when } from "jest-when";
import type { DeploymentStatusEvent } from "@octokit/webhooks-types";
import { dynamodb as ddb } from "config/dynamodb";
import { createHashWithoutSharedSecret } from "utils/encryption";
Expand Down Expand Up @@ -73,7 +71,6 @@ describe("DeploymentWebhookHandler", () => {
let payload: DeploymentStatusEvent;
describe("Persistent to dynamoDB", () => {
beforeEach(async () => {
when(booleanFlag).calledWith(BooleanFlags.USE_DYNAMODB_FOR_DEPLOYMENT_WEBHOOK, expect.anything()).mockResolvedValue(true);
payload = JSON.parse(JSON.stringify(deployment_status.payload)) as DeploymentStatusEvent;
});
it("should call to persist deployment info for success deployment status", async () => {
Expand Down
18 changes: 8 additions & 10 deletions src/github/deployment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { getJiraClient, DeploymentsResult } from "../jira/client/jira-client";
import { sqsQueues } from "../sqs/queues";
import type { DeploymentStatusEvent } from "@octokit/webhooks-types";
import Logger from "bunyan";
import { isBlocked, booleanFlag, BooleanFlags } from "config/feature-flags";
import { isBlocked } from "config/feature-flags";
import { GitHubInstallationClient } from "./client/github-installation-client";
import { WebhookContext } from "routes/github/webhook/webhook-context";
import { cacheSuccessfulDeploymentInfo } from "services/deployment-cache-service";
Expand All @@ -15,15 +15,13 @@ import { getCloudOrServerFromGitHubAppId } from "utils/get-cloud-or-server";

export const deploymentWebhookHandler = async (context: WebhookContext, jiraClient, _util, gitHubInstallationId: number, subscription: Subscription): Promise<void> => {
if (context.payload.deployment_status.state === "success") {
if (await booleanFlag(BooleanFlags.USE_DYNAMODB_FOR_DEPLOYMENT_WEBHOOK, subscription.jiraHost)) {
await tryCacheSuccessfulDeploymentInfo(
subscription.jiraHost,
context.gitHubAppConfig.gitHubBaseUrl,
context.gitHubAppConfig.gitHubAppId,
context.payload,
context.log
);
}
await tryCacheSuccessfulDeploymentInfo(
subscription.jiraHost,
context.gitHubAppConfig.gitHubBaseUrl,
context.gitHubAppConfig.gitHubAppId,
context.payload,
context.log
);
}

await sqsQueues.deployment.sendMessage({
Expand Down
Loading

0 comments on commit e1b3e5b

Please sign in to comment.