Skip to content
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
25 changes: 22 additions & 3 deletions src/renderer/typesGitHub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,16 @@ export type UserType =
| 'User';

/**
* Note: draft and merged are not official states in the GitHub API.
* These are derived from the pull request's `merged` and `draft` properties.
* Note: draft, merged and queued are not official states in the GitHub API.
* These are derived from the pull request's `merged` and `draft` properties, or
* by checking the PR merge queue state.
*/
export type PullRequestStateType = 'closed' | 'draft' | 'merged' | 'open';
export type PullRequestStateType =
| 'closed'
| 'draft'
| 'merged'
| 'open'
| 'queued';

export type StateType =
| CheckSuiteStatus
Expand Down Expand Up @@ -497,6 +503,19 @@ export interface GraphQLSearch<T> {
};
}

export interface GraphQLMergeQueue {
data: {
repository: {
pullRequest: {
mergeQueueEntry: {
state: string;
position: number;
} | null;
};
};
};
}

export interface Discussion {
number: number;
title: string;
Expand Down
26 changes: 26 additions & 0 deletions src/renderer/utils/api/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import type {
Commit,
CommitComment,
Discussion,
GraphQLMergeQueue,
GraphQLSearch,
Issue,
IssueOrPullRequestComment,
Expand All @@ -25,6 +26,7 @@ import type {
import { isAnsweredDiscussionFeatureSupported } from '../features';
import { rendererLogError } from '../logger';
import { QUERY_SEARCH_DISCUSSIONS } from './graphql/discussions';
import { QUERY_CHECK_MERGE_QUEUE_FOR_PR } from './graphql/pullRequests';
import { formatAsGitHubSearchSyntax } from './graphql/utils';
import { apiRequestAuth } from './request';
import { getGitHubAPIBaseUrl, getGitHubGraphQLUrl } from './utils';
Expand Down Expand Up @@ -285,3 +287,27 @@ export async function getLatestDiscussion(
);
}
}

/**
* Check if PR is in merge queue.
*/
export async function queryMergeQueueForPr(
notification: Notification,
prNumber: number,
): AxiosPromise<GraphQLMergeQueue> {
const url = getGitHubGraphQLUrl(notification.account.hostname);

return apiRequestAuth(
url.toString() as Link,
'POST',
notification.account.token,
{
query: print(QUERY_CHECK_MERGE_QUEUE_FOR_PR),
variables: {
owner: notification.repository.owner.login,
repository: notification.repository.name,
prNumber: prNumber,
},
},
);
}
18 changes: 18 additions & 0 deletions src/renderer/utils/api/graphql/pullRequests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import gql from 'graphql-tag';

export const QUERY_CHECK_MERGE_QUEUE_FOR_PR = gql`
query checkMergeQueueForPR(
$owner: String!
$repository: String!
$prNumber: Int!
) {
repository(owner: $owner, name: $repository) {
pullRequest(number: $prNumber) {
mergeQueueEntry {
state
position
}
}
}
}
`;
2 changes: 2 additions & 0 deletions src/renderer/utils/notifications/handlers/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ export class DefaultHandler implements NotificationTypeHandler {
case 'RESOLVED':
case 'merged':
return IconColor.PURPLE;
case 'queued':
return IconColor.YELLOW;
default:
return IconColor.GRAY;
}
Expand Down
22 changes: 22 additions & 0 deletions src/renderer/utils/notifications/handlers/pullRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { FC } from 'react';
import type { OcticonProps } from '@primer/octicons-react';
import {
GitMergeIcon,
GitMergeQueueIcon,
GitPullRequestClosedIcon,
GitPullRequestDraftIcon,
GitPullRequestIcon,
Expand All @@ -23,6 +24,7 @@ import {
getIssueOrPullRequestComment,
getPullRequest,
getPullRequestReviews,
queryMergeQueueForPr,
} from '../../api/client';
import { isStateFilteredOut, isUserFilteredOut } from '../filters/filter';
import { DefaultHandler } from './default';
Expand All @@ -44,6 +46,12 @@ class PullRequestHandler extends DefaultHandler {
prState = 'merged';
} else if (pr.draft) {
prState = 'draft';
} else if (prState === 'open') {
const mergeQueue = await isPRInMergeQueue(notification, pr.number);

if (mergeQueue) {
prState = 'queued';
}
}

// Return early if this notification would be hidden by state filters
Expand Down Expand Up @@ -95,6 +103,8 @@ class PullRequestHandler extends DefaultHandler {
return GitPullRequestClosedIcon;
case 'merged':
return GitMergeIcon;
case 'queued':
return GitMergeQueueIcon;
default:
return GitPullRequestIcon;
}
Expand Down Expand Up @@ -173,3 +183,15 @@ export function parseLinkedIssuesFromPr(pr: PullRequest): string[] {

return linkedIssues;
}

export async function isPRInMergeQueue(
notification: Notification,
prNumber: number,
): Promise<boolean> {
const mergeQueueResponse = await queryMergeQueueForPr(notification, prNumber);

const mergeQueueEntry =
mergeQueueResponse.data.data.repository.pullRequest.mergeQueueEntry;

return mergeQueueEntry !== null;
}
Loading