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

Removing FF for Draft PR #2524

Merged
merged 1 commit into from
Oct 30, 2023
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
1 change: 0 additions & 1 deletion src/config/feature-flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ const launchdarklyClient = LaunchDarkly.init(envVars.LAUNCHDARKLY_KEY || "", {

export enum BooleanFlags {
MAINTENANCE_MODE = "maintenance-mode",
INNO_DRAFT_PR = "inno-draft-pr",
VERBOSE_LOGGING = "verbose-logging",
SEND_PR_COMMENTS_TO_JIRA = "send-pr-comments-to-jira_zy5ib",
JIRA_ADMIN_CHECK = "jira-admin-check",
Expand Down
4 changes: 1 addition & 3 deletions src/sync/pull-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,11 @@ const getPullRequestTaskGraphQL = async (

const response = await gitHubInstallationClient.getPullRequestPage(repository.owner.login, repository.name, perPage, cursor);

const isDraftPrFfOn = await booleanFlag(BooleanFlags.INNO_DRAFT_PR);

const filteredByCreatedSince = response.repository?.pullRequests?.edges
.filter(pull => !createdSince || pull.node.createdAt > createdSince.toISOString());
const alwaysSend = await shouldSendAll("prs-backfill", jiraHost, logger);
const pullRequests = filteredByCreatedSince
?.map((edge) => transformPullRequest(repository, jiraHost, edge.node, alwaysSend, logger, isDraftPrFfOn))
?.map((edge) => transformPullRequest(repository, jiraHost, edge.node, alwaysSend, logger))
?.filter((pr) => pr !== undefined) || [];

(logger.fields || {}).prNumberArray = pullRequests.map(pull => createHashWithSharedSecret(String(pull?.id)));
Expand Down
26 changes: 6 additions & 20 deletions src/transforms/transform-pull-request.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import multipleReviewersWithMultipleReviews
import { GitHubInstallationClient } from "~/src/github/client/github-installation-client";
import { getInstallationId } from "~/src/github/client/installation-id";
import { getLogger } from "config/logger";
import { booleanFlag, BooleanFlags, shouldSendAll } from "config/feature-flags";
import { shouldSendAll } from "config/feature-flags";
import _, { cloneDeep } from "lodash";
import { createLogger } from "bunyan";
import { when } from "jest-when";
Expand All @@ -21,10 +21,6 @@ describe("pull_request transform REST", () => {
beforeEach(() => {
mockSystemTime(12345678);
client = new GitHubInstallationClient(getInstallationId(gitHubInstallationId), gitHubCloudConfig, jiraHost, { trigger: "test" }, getLogger("test"));

when(booleanFlag).calledWith(
BooleanFlags.INNO_DRAFT_PR
).mockResolvedValue(true);
});

it("should not contain branches on the payload if pull request status is closed.", async () => {
Expand Down Expand Up @@ -746,9 +742,7 @@ describe("pull_request transform GraphQL", () => {

const { updatedAt } = payload;

const isDraftPrFFOn = true;

const data = transformPullRequest(REPO_OBJ, jiraHost, payload as any, true, logger, isDraftPrFFOn);
const data = transformPullRequest(REPO_OBJ, jiraHost, payload as any, true, logger);

expect(data).toMatchObject({
author: {
Expand Down Expand Up @@ -788,9 +782,7 @@ describe("pull_request transform GraphQL", () => {

const { updatedAt } = payload;

const isDraftPrFFOn = true;

const data = transformPullRequest(REPO_OBJ, jiraHost, payload as any, true, logger, isDraftPrFFOn);
const data = transformPullRequest(REPO_OBJ, jiraHost, payload as any, true, logger);

expect(data).toStrictEqual({
author: {
Expand Down Expand Up @@ -832,9 +824,7 @@ describe("pull_request transform GraphQL", () => {

const { updatedAt } = payload;

const isDraftPrFFOn = true;

const data = await transformPullRequest(REPO_OBJ, jiraHost, payload as any, true, logger, isDraftPrFFOn);
const data = await transformPullRequest(REPO_OBJ, jiraHost, payload as any, true, logger);

expect(data).toStrictEqual({
author: {
Expand Down Expand Up @@ -874,9 +864,7 @@ describe("pull_request transform GraphQL", () => {
const payload = { ...createPullPayload(title), author: {} };
payload.reviews = createReview("APPROVED", "[email protected]");

const isDraftPrFFOn = true;

const data = await transformPullRequest(REPO_OBJ, jiraHost, payload as any, true, logger, isDraftPrFFOn);
const data = await transformPullRequest(REPO_OBJ, jiraHost, payload as any, true, logger);
const { updatedAt } = payload;

expect(data).toMatchObject({
Expand Down Expand Up @@ -915,9 +903,7 @@ describe("pull_request transform GraphQL", () => {
const payload = { ...createPullPayload(title), author: {} };
payload.reviews = createMultipleReviews();

const isDraftPrFFOn = true;

const data = await transformPullRequest(REPO_OBJ, jiraHost, payload as any, true, logger, isDraftPrFFOn);
const data = await transformPullRequest(REPO_OBJ, jiraHost, payload as any, true, logger);

expect({ firstReviewStatus: data?.reviewers[0] }).toEqual(expect.objectContaining({
firstReviewStatus: expect.objectContaining({
Expand Down
22 changes: 7 additions & 15 deletions src/transforms/transform-pull-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,10 @@ import { booleanFlag, BooleanFlags, shouldSendAll } from "config/feature-flags";
import { getLogger } from "config/logger";
import { Repository } from "models/subscription";

export const mapStatus = (status: string, draft: boolean, isDraftPrFfOn: boolean, merged_at?: string) => {
export const mapStatus = (status: string, draft: boolean, merged_at?: string) => {
if (status.toLowerCase() === "merged") return "MERGED";
if (isDraftPrFfOn) {
if (status.toLowerCase() === "open" && !draft) return "OPEN";
if (status.toLowerCase() === "open" && draft) return "DRAFT";
} else {
if (status.toLowerCase() === "open") return "OPEN";
}
if (status.toLowerCase() === "open" && !draft) return "OPEN";
if (status.toLowerCase() === "open" && draft) return "DRAFT";
if (status.toLowerCase() === "closed" && merged_at) return "MERGED";
if (status.toLowerCase() === "closed" && !merged_at) return "DECLINED";
if (status.toLowerCase() === "declined") return "DECLINED";
Expand Down Expand Up @@ -139,13 +135,11 @@ export const transformPullRequestRest = async (
return undefined;
}

const isDraftPrFfOn = await booleanFlag(BooleanFlags.INNO_DRAFT_PR);

const branches = await getBranches(gitHubInstallationClient, pullRequest, issueKeys, log);
// Need to get full name from a REST call as `pullRequest.user.login` doesn't have it
const author = getJiraAuthor(user, await getGithubUser(gitHubInstallationClient, user?.login, log));
const reviewers = await mapReviewsRest(reviews, gitHubInstallationClient, log);
const status = mapStatus(state, draft, isDraftPrFfOn, merged_at);
const status = mapStatus(state, draft, merged_at);

return {
...transformRepositoryDevInfoBulk(base.repo, gitHubInstallationClient.baseUrl),
Expand Down Expand Up @@ -177,9 +171,7 @@ export const transformPullRequestRest = async (
// Reason: If "Automatically delete head branches" is enabled, the branch deleted and PR merged events might be sent out
// “at the same time” and received out of order, which causes the branch being created again.
const getBranches = async (gitHubInstallationClient: GitHubInstallationClient, pullRequest: Octokit.PullsGetResponse, issueKeys: string[], logger: Logger) => {
const isDraftPrFfOn = await booleanFlag(BooleanFlags.INNO_DRAFT_PR);

if (mapStatus(pullRequest.state, pullRequest.draft, isDraftPrFfOn, pullRequest.merged_at) === "MERGED") {
if (mapStatus(pullRequest.state, pullRequest.draft, pullRequest.merged_at) === "MERGED") {
return [];
}

Expand Down Expand Up @@ -208,7 +200,7 @@ const getBranches = async (gitHubInstallationClient: GitHubInstallationClient, p
];
};

export const transformPullRequest = (repository: Repository, _jiraHost: string, pullRequest: pullRequestNode, alwaysSend: boolean, log: Logger, isDraftPrFfOn: boolean) => {
export const transformPullRequest = (repository: Repository, _jiraHost: string, pullRequest: pullRequestNode, alwaysSend: boolean, log: Logger) => {
const issueKeys = extractIssueKeysFromPr(pullRequest);

if (isEmpty(issueKeys) && !alwaysSend) {
Expand All @@ -219,7 +211,7 @@ export const transformPullRequest = (repository: Repository, _jiraHost: string,
return undefined;
}

const status = mapStatus(pullRequest.state, pullRequest.draft, isDraftPrFfOn, pullRequest.mergedAt);
const status = mapStatus(pullRequest.state, pullRequest.draft, pullRequest.mergedAt);

return {
author: getJiraAuthor(pullRequest.author),
Expand Down