Skip to content

Commit 8b6d536

Browse files
Copilotalexr00
andauthored
Support ${issueType} in githubIssues.issueBranchTitle (#8712)
* Initial plan * Add ${issueType} template variable for issueBranchTitle and other variable substitution settings Agent-Logs-Url: https://github.com/microsoft/vscode-pull-request-github/sessions/fcd74dc6-13f6-4b1d-bd6d-f62927df79d2 Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
1 parent b09bcbf commit 8b6d536

8 files changed

Lines changed: 61 additions & 3 deletions

File tree

documentation/IssueFeatures.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,3 +111,6 @@ Some of the settings (ex. `githubIssues.workingIssueFormatScm` and `githubIssues
111111
- `${owner}`: The owner of the current repository.
112112
- `${sanitizedIssueTitle}`: The title of the current issue with characters that git forbids removed.
113113
- `${sanitizedLowercaseIssueTitle}`: The lowercase title of the current issue with characters that git forbids removed.
114+
- `${issueType}`: The name of the issue type (e.g. `Feature`, `Hotfix`), if the issue has an issue type set. If the issue does not have an issue type, the variable is left as-is.
115+
- `${sanitizedIssueType}`: The issue type name with characters that git forbids removed.
116+
- `${sanitizedLowercaseIssueType}`: The lowercase issue type name with characters that git forbids removed.

package.nls.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@
125125
"githubIssues.ignoreUserCompletionTrigger.description": "Languages that the '@' character should not be used to trigger user completion suggestions.",
126126
"githubIssues.ignoreUserCompletionTrigger.items": "Language that user completions should not trigger on '@'.",
127127
"githubIssues.issueBranchTitle.markdownDescription": {
128-
"message": "Advanced settings for the name of the branch that is created when you start working on an issue. \n- `${user}` will be replaced with the currently logged in username \n- `${issueNumber}` will be replaced with the current issue number \n- `${sanitizedIssueTitle}` will be replaced with the issue title, with all spaces and unsupported characters (https://git-scm.com/docs/git-check-ref-format) removed. For lowercase, use `${sanitizedLowercaseIssueTitle}` ",
128+
"message": "Advanced settings for the name of the branch that is created when you start working on an issue. \n- `${user}` will be replaced with the currently logged in username \n- `${issueNumber}` will be replaced with the current issue number \n- `${issueType}` will be replaced with the issue type name (e.g. `Feature`, `Hotfix`). For branch-safe variants, use `${sanitizedIssueType}` or `${sanitizedLowercaseIssueType}` \n- `${sanitizedIssueTitle}` will be replaced with the issue title, with all spaces and unsupported characters (https://git-scm.com/docs/git-check-ref-format) removed. For lowercase, use `${sanitizedLowercaseIssueTitle}` ",
129129
"comment": [
130130
"{Locked='${...}'}",
131131
"Do not translate what's inside of the '${..}'. It is an internal syntax for the extension"

src/github/graphql.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,9 @@ export interface Issue {
733733
totalCount: number;
734734
}
735735
reactionGroups: ReactionGroup[];
736+
issueType?: {
737+
name: string;
738+
} | null;
736739
}
737740

738741

src/github/interface.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ export interface Issue {
221221
commentCount: number;
222222
reactionCount: number;
223223
reactions: Reaction[];
224+
issueType?: string;
224225
}
225226

226227
export interface IssueReference {

src/github/queries.gql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ fragment IssueBase on Issue {
110110
}
111111
url
112112
}
113+
issueType {
114+
name
115+
}
113116
}
114117

115118
fragment IssueFragment on Issue {

src/github/queriesExtra.gql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@ fragment IssueBase on Issue {
119119
}
120120
}
121121
}
122+
issueType {
123+
name
124+
}
122125
}
123126

124127
fragment IssueFragment on Issue {

src/github/utils.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1052,7 +1052,8 @@ export async function parseGraphQLIssue(issue: GraphQL.Issue, githubRepository:
10521052
comments: issue.comments.nodes?.map(comment => parseIssueComment(comment, githubRepository)),
10531053
reactionCount: issue.reactions.totalCount,
10541054
reactions: parseGraphQLReaction(issue.reactionGroups),
1055-
commentCount: issue.comments.totalCount
1055+
commentCount: issue.comments.totalCount,
1056+
issueType: issue.issueType?.name
10561057
};
10571058
}
10581059

@@ -1865,6 +1866,15 @@ export function variableSubstitution(
18651866
case 'sanitizedLowercaseIssueTitle':
18661867
result = issueModel ? sanitizeIssueTitle(issueModel.title).toLowerCase() : match;
18671868
break;
1869+
case 'issueType':
1870+
result = issueModel?.item.issueType ? issueModel.item.issueType : match;
1871+
break;
1872+
case 'sanitizedIssueType':
1873+
result = issueModel?.item.issueType ? sanitizeIssueTitle(issueModel.item.issueType) : match;
1874+
break;
1875+
case 'sanitizedLowercaseIssueType':
1876+
result = issueModel?.item.issueType ? sanitizeIssueTitle(issueModel.item.issueType).toLowerCase() : match;
1877+
break;
18681878
case 'today':
18691879
result = computeSinceValue(extra);
18701880
break;

src/test/github/utils.test.ts

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import { default as assert } from 'assert';
7-
import { getPRFetchQuery, sanitizeIssueTitle } from '../../github/utils';
7+
import { getPRFetchQuery, sanitizeIssueTitle, variableSubstitution } from '../../github/utils';
8+
import { IssueModel } from '../../github/issueModel';
89

910
describe('utils', () => {
1011

@@ -41,4 +42,38 @@ describe('utils', () => {
4142
});
4243
});
4344
});
45+
46+
describe('variableSubstitution', () => {
47+
function makeIssueModel(overrides: { title?: string; number?: number; issueType?: string } = {}): IssueModel {
48+
const number = overrides.number ?? 42;
49+
const title = overrides.title ?? 'Some Issue';
50+
return {
51+
number,
52+
title,
53+
item: {
54+
issueType: overrides.issueType,
55+
},
56+
} as unknown as IssueModel;
57+
}
58+
59+
it('replaces ${issueType} with the issue type name', () => {
60+
const result = variableSubstitution('${issueType}-${issueNumber}', makeIssueModel({ issueType: 'Feature', number: 7 }));
61+
assert.strictEqual(result, 'Feature-7');
62+
});
63+
64+
it('replaces ${sanitizedIssueType} with a branch-safe issue type', () => {
65+
const result = variableSubstitution('${sanitizedIssueType}-${issueNumber}', makeIssueModel({ issueType: 'Production Bug Fix', number: 7 }));
66+
assert.strictEqual(result, 'Production-Bug-Fix-7');
67+
});
68+
69+
it('replaces ${sanitizedLowercaseIssueType} with a lowercase branch-safe issue type', () => {
70+
const result = variableSubstitution('${sanitizedLowercaseIssueType}-${issueNumber}', makeIssueModel({ issueType: 'Production Bug Fix', number: 7 }));
71+
assert.strictEqual(result, 'production-bug-fix-7');
72+
});
73+
74+
it('leaves ${issueType} unsubstituted when the issue has no issue type', () => {
75+
const result = variableSubstitution('${issueType}-${issueNumber}', makeIssueModel({ issueType: undefined, number: 7 }));
76+
assert.strictEqual(result, '${issueType}-7');
77+
});
78+
});
4479
});

0 commit comments

Comments
 (0)