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

add 'draft' state for pull-requests #2270

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion docs/DevInfoAPI.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions docs/jira-dev-info-0.10-swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,7 @@ definitions:
readOnly: true
enum:
- "OPEN"
- "DRAFT"
- "MERGED"
- "DECLINED"
- "UNKNOWN"
Expand Down
2 changes: 2 additions & 0 deletions src/github/client/github-queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export type pullRequestNode = {
title: string;
body: string;
url: string;
draft: boolean;
baseRef?: {
name: string;
repository: {
Expand Down Expand Up @@ -184,6 +185,7 @@ export const getPullRequests = `query ($owner: String!, $repo: String!, $per_pag
title
body
url
draft
baseRef {
name
repository {
Expand Down
2 changes: 1 addition & 1 deletion src/transforms/transform-pull-request.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
15 changes: 9 additions & 6 deletions src/transforms/transform-pull-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -98,7 +100,8 @@ export const transformPullRequestRest = async (
state,
merged_at,
title,
html_url
html_url,
draft
} = pullRequest;

const issueKeys = extractIssueKeysFromPrRest(pullRequest);
Expand All @@ -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),
Expand Down Expand Up @@ -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 [];
}

Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/api/transform-pull-request-list.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -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": {
Expand Down Expand Up @@ -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": {
Expand Down