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
34 changes: 34 additions & 0 deletions lib/modules/platform/github/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ query($owner: String!, $name: String!, $user: String) {
first: 5
) {
nodes {
id
number
state
title
Expand Down Expand Up @@ -57,6 +58,7 @@ query(
hasNextPage
}
nodes {
id
number
state
title
Expand Down Expand Up @@ -85,3 +87,35 @@ mutation EnablePullRequestAutoMerge(
}
}
`;

export const pinIssueMutation = `
mutation PinIssue(
$issueId: ID!,
) {
pinIssue(
input: {
issueId: $issueId,
}
) {
issue {
number
}
}
}
`;

export const unpinIssueMutation = `
mutation UnpinIssue(
$issueId: ID!,
) {
unpinIssue(
input: {
issueId: $issueId,
}
) {
issue {
number
}
}
}
`;
16 changes: 16 additions & 0 deletions lib/modules/platform/github/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ import { coerceRestPr, githubApi, mapMergeStartegy } from './common';
import {
enableAutoMergeMutation,
getIssuesQuery,
pinIssueMutation,
repoInfoQuery,
} from './graphql';
import { GithubIssueCache, GithubIssue as Issue } from './issue';
Expand Down Expand Up @@ -1371,13 +1372,22 @@ async function closeIssue(issueNumber: number): Promise<void> {
GithubIssueCache.updateIssue(closedIssue);
}

async function pinIssue(issueId: string): Promise<void> {
logger.debug(`pinIssue(${issueId})`);
await githubApi.requestGraphql(pinIssueMutation, {
variables: { issueId },
});
logger.debug('Issue pinned');
}

export async function ensureIssue({
title,
reuseTitle,
body: rawBody,
labels,
once = false,
shouldReOpen = true,
isPinned = false,
}: EnsureIssueConfig): Promise<EnsureIssueResult | null> {
logger.debug(`ensureIssue(${title})`);
/* v8 ignore next */
Expand Down Expand Up @@ -1446,6 +1456,9 @@ export async function ensureIssue({
);
GithubIssueCache.updateIssue(updatedIssue);
logger.debug('Issue updated');
if (isPinned && updatedIssue.node_id) {
await pinIssue(updatedIssue.node_id);
}
return 'updated';
}
}
Expand All @@ -1463,6 +1476,9 @@ export async function ensureIssue({
logger.info('Issue created');
// reset issueList so that it will be fetched again as-needed
GithubIssueCache.updateIssue(createdIssue);
if (isPinned && createdIssue.node_id) {
await pinIssue(createdIssue.node_id);
}
return 'created';
} catch (err) /* v8 ignore next */ {
if (err.body?.message?.startsWith('Issues are disabled for this repo')) {
Expand Down
26 changes: 19 additions & 7 deletions lib/modules/platform/github/issue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,40 @@ const GithubIssueBase = z.object({
state: z.string().transform((val) => val.toLowerCase()),
title: z.string(),
body: z.string(),
node_id: z.string().optional(),
});

interface TransformedIssue {
number: number;
state: string;
title: string;
body: string;
lastModified: string;
node_id?: string;
}

const GithubGraphqlIssue = GithubIssueBase.extend({
id: z.string().optional(),
updatedAt: z.string(),
}).transform((issue) => {
}).transform((issue): TransformedIssue => {
const lastModified = issue.updatedAt;
const { number, state, title, body } = issue;
return { number, state, title, body, lastModified };
const { number, state, title, body, id } = issue;
const node_id = id ?? issue.node_id;
return { number, state, title, body, lastModified, node_id };
});

const GithubRestIssue = GithubIssueBase.extend({
updated_at: z.string(),
}).transform((issue) => {
}).transform((issue): TransformedIssue => {
const lastModified = issue.updated_at;
const { number, state, title, body } = issue;
return { number, state, title, body, lastModified };
const { number, state, title, body, node_id } = issue;
return { number, state, title, body, lastModified, node_id };
});

export const GithubIssue = z.union([GithubGraphqlIssue, GithubRestIssue]);
export type GithubIssue = z.infer<typeof GithubIssue>;

type CacheData = Record<number, GithubIssue>;
interface CacheData extends Record<number, GithubIssue> {}

export class GithubIssueCache {
private static reset(cacheData: CacheData | null): void {
Expand Down
1 change: 1 addition & 0 deletions lib/modules/platform/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ export interface EnsureIssueConfig {
once?: boolean;
shouldReOpen?: boolean;
confidential?: boolean;
isPinned?: boolean;
}
export interface BranchStatusConfig {
branchName: string;
Expand Down
1 change: 1 addition & 0 deletions lib/workers/repository/dependency-dashboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,7 @@ export async function ensureDependencyDashboard(
body: platform.massageMarkdown(issueBody, config.rebaseLabel),
labels: config.dependencyDashboardLabels,
confidential: config.confidential,
isPinned: true,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be configurable via a new config option, so users can decide for themselves.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, also take a look at this comment for directions about how to set value for the new config option and whether the pinning of an issue needs additional permissions or not.

});
}
}
Expand Down
Loading