diff --git a/docs/DevInfoAPI.json b/docs/DevInfoAPI.json index acd0c020cb..dc8ea4ffeb 100644 --- a/docs/DevInfoAPI.json +++ b/docs/DevInfoAPI.json @@ -434,7 +434,7 @@ "type" : "string", "description" : "The status of the pull request. Priority applies between these states with preference given in the order OPEN, MERGED, DECLINED, UNKNOWN", "readOnly" : true, - "enum" : [ "OPEN", "MERGED", "DECLINED", "UNKNOWN" ] + "enum" : [ "OPEN", "DRAFT", "MERGED", "DECLINED", "UNKNOWN" ] }, "title" : { "type" : "string", diff --git a/docs/jira-dev-info-0.10-swagger.yaml b/docs/jira-dev-info-0.10-swagger.yaml index 23637e29e9..9b81214a45 100644 --- a/docs/jira-dev-info-0.10-swagger.yaml +++ b/docs/jira-dev-info-0.10-swagger.yaml @@ -773,6 +773,7 @@ definitions: readOnly: true enum: - "OPEN" + - "DRAFT" - "MERGED" - "DECLINED" - "UNKNOWN" diff --git a/src/github/client/github-queries.ts b/src/github/client/github-queries.ts index 23a9d5919b..01456ca494 100644 --- a/src/github/client/github-queries.ts +++ b/src/github/client/github-queries.ts @@ -77,6 +77,7 @@ export type pullRequestNode = { title: string; body: string; url: string; + draft: boolean; baseRef?: { name: string; repository: { @@ -184,6 +185,7 @@ export const getPullRequests = `query ($owner: String!, $repo: String!, $per_pag title body url + draft baseRef { name repository { diff --git a/src/transforms/transform-pull-request.test.ts b/src/transforms/transform-pull-request.test.ts index c13fb3da7b..34a7fc76eb 100644 --- a/src/transforms/transform-pull-request.test.ts +++ b/src/transforms/transform-pull-request.test.ts @@ -195,7 +195,7 @@ describe("pull_request transform", () => { sourceBranch: "use-the-force", sourceBranchUrl: "https://github.com/integrations/test/tree/use-the-force", - status: "OPEN", + status: "DRAFT", timestamp: updated_at, title: title, url: "https://github.com/integrations/test/pull/51", diff --git a/src/transforms/transform-pull-request.ts b/src/transforms/transform-pull-request.ts index 962710e4e0..0cc61b28e3 100644 --- a/src/transforms/transform-pull-request.ts +++ b/src/transforms/transform-pull-request.ts @@ -10,9 +10,11 @@ import { JiraReview } from "../interfaces/jira"; import { transformRepositoryDevInfoBulk } from "~/src/transforms/transform-repository"; import { pullRequestNode } from "~/src/github/client/github-queries"; -const mapStatus = (status: string, merged_at?: string) => { +const mapStatus = (status: string, merged_at?: string, draft?:boolean) => { if (status.toLowerCase() === "merged") return "MERGED"; - if (status.toLowerCase() === "open") return "OPEN"; + if (status.toLowerCase() === "open") + if (draft) return "DRAFT"; + else return "OPEN"; if (status.toLowerCase() === "closed" && merged_at) return "MERGED"; if (status.toLowerCase() === "closed" && !merged_at) return "DECLINED"; if (status.toLowerCase() === "declined") return "DECLINED"; @@ -98,7 +100,8 @@ export const transformPullRequestRest = async ( state, merged_at, title, - html_url + html_url, + draft } = pullRequest; const issueKeys = extractIssueKeysFromPrRest(pullRequest); @@ -116,7 +119,7 @@ export const transformPullRequestRest = async ( // 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)); const reviewers = await mapReviewsRest(reviews, gitHubInstallationClient); - const status = mapStatus(state, merged_at); + const status = mapStatus(state, merged_at, draft); return { ...transformRepositoryDevInfoBulk(base.repo, gitHubInstallationClient.baseUrl), @@ -147,7 +150,7 @@ export const transformPullRequestRest = async ( // Do not send the branch on the payload when the Pull Request Merged event is called. // 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[]) => { - if (mapStatus(pullRequest.state, pullRequest.merged_at) === "MERGED") { + if (mapStatus(pullRequest.state, pullRequest.merged_at, pullRequest.draft) === "MERGED") { return []; } @@ -187,7 +190,7 @@ export const transformPullRequest = (_jiraHost: string, pullRequest: pullRequest return undefined; } - const status = mapStatus(pullRequest.state, pullRequest.mergedAt); + const status = mapStatus(pullRequest.state, pullRequest.mergedAt, pullRequest.draft); try { return { diff --git a/test/fixtures/api/transform-pull-request-list.json b/test/fixtures/api/transform-pull-request-list.json index 9db4cb16f7..0e85e50515 100644 --- a/test/fixtures/api/transform-pull-request-list.json +++ b/test/fixtures/api/transform-pull-request-list.json @@ -9,6 +9,7 @@ "issue_url": "https://api.github.com/repos/integrations/test/issues/51", "number": 51, "state": "merged", + "draft": false, "locked": false, "title": "[TES-123] Branch payload Test", "user": { @@ -322,6 +323,7 @@ "issue_url": "https://api.github.com/repos/integrations/test/issues/51", "number": 51, "state": "open", + "draft": false, "locked": false, "title": "Testing force pushes", "user": { @@ -636,6 +638,7 @@ "issue_url": "https://api.github.com/repos/integrations/test/issues/51", "number": 51, "state": "open", + "draft": true, "locked": false, "title": "Testing force pushes", "user": {