提交 b85cbe51 编写于 作者: T Tomas Vik

Merge branch '286-add-mr-s-i-m-reviewing-to-sidebar-lists-2' into 'main'

feat: add "Merge requests I'm reviewing" custom query

See merge request gitlab-org/gitlab-vscode-extension!226
......@@ -228,6 +228,8 @@ Each query is an entry of the json array. Each entry can have the following valu
**`pipelineId`** _(required: false)_ : Returns vulnerabilities belonging to specified pipeline. "branch" returns vulnerabilities belonging to latest pipeline of the current branch. Works only with vulnerabilities.
**`reviewer`** _(required: false)_ : Returns GitLab Merge Requests assigned for review to the given username. When set to `"<current_user>"`, the extension uses the current user's username.
## Usage
- Open up Command Palette by pressing `Cmd+Shift+P`.
......
......@@ -572,6 +572,10 @@
"pipelineId": {
"type": "number | string",
"description": "Returns vulnerabilities belonging to specified pipeline. \"branch\" returns vulnerabilities belonging to latest pipeline of the current branch. Works only with vulnerabilities"
},
"reviewer": {
"type": "string",
"description": "Returns GitLab Merge Requests assigned for review to the given username. When set to \"<current_user>\", the extension uses the current user's username."
}
}
},
......@@ -597,6 +601,13 @@
"state": "opened",
"noItemText": "There is no MR assigned to you."
},
{
"name": "Merge requests I'm reviewing",
"type": "merge_requests",
"reviewer": "<current_user>",
"state": "opened",
"noItemText": "There is no MR for you to review."
},
{
"name": "Merge requests created by me",
"type": "merge_requests",
......
......@@ -31,4 +31,5 @@ export interface CustomQuery {
searchIn: string;
pipelineId?: number | 'branch';
noItemText: string;
reviewer?: string;
}
......@@ -191,6 +191,13 @@ describe('fetchIssueables', () => {
});
});
it('sets reviewer parameter', async () => {
setupFetchIssuable();
await fetchIssuablesHelper({ type: CustomQueryType.MR, reviewer: 'reviewer' });
const search = new URLSearchParams(request.mock.calls[1][0]);
expect(search.get('reviewer_username')).toEqual('reviewer');
});
describe('searchIn parameters', () => {
it('sets "all" parameter', async () => {
setupFetchIssuable();
......
......@@ -146,9 +146,10 @@ export async function fetchCurrentPipelineProject(workspaceFolder: string) {
}
}
export async function fetchCurrentUser() {
export async function fetchCurrentUser(): Promise<RestUser> {
try {
const { response: user } = await fetch('/user');
if (!user) throw new Error('Could not retrieve current user.');
return user;
} catch (e) {
throw new ApiError(e, 'get current user');
......@@ -217,7 +218,7 @@ type QueryValue = string | boolean | string[] | number | undefined;
export async function fetchIssuables(params: CustomQuery, workspaceFolder: string) {
const { type, scope, state, author, assignee, wip } = params;
let { searchIn, pipelineId } = params;
let { searchIn, pipelineId, reviewer } = params;
const config = {
type: type || 'merge_requests',
scope: scope || 'all',
......@@ -291,6 +292,17 @@ export async function fetchIssuables(params: CustomQuery, workspaceFolder: strin
search.append('assignee_id', (assigneeUser && assigneeUser.id) || '-1');
}
/**
* Reviewer parameters
*/
if (reviewer) {
if (reviewer === '<current_user>') {
const user = await fetchCurrentUser();
reviewer = user.username;
}
search.append('reviewer_username', reviewer);
}
/**
* Search in parameters
*/
......
......@@ -31,7 +31,7 @@ async function getLink(linkTemplate: string, workspaceFolder: string) {
const project = await gitLabService.fetchCurrentProject(workspaceFolder);
assert(project, 'Failed to fetch project');
return linkTemplate.replace('$userId', user.id).replace('$projectUrl', project.webUrl);
return linkTemplate.replace('$userId', user.id.toString()).replace('$projectUrl', project.webUrl);
}
async function openLink(linkTemplate: string, workspaceFolder: string) {
......
......@@ -62,3 +62,11 @@ interface RestPipeline {
project_id: number;
web_url: string;
}
// Incomplete reference of the GitLab user model
interface RestUser {
id: number;
username: string;
email: string;
state: string;
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册