提交 4f4f61cc 编写于 作者: J Julien Duponchelle

Allow to use a different remote for the pipeline

When you work using a fork the issue will be
associated with the origin project but your
pipeline will run in the context of the
fork project.

This commit allow user to configure a different
remote to watch their pipeline in order to
adapt to this workflow.

Ref #59
上级 c083c676
......@@ -97,7 +97,11 @@ If you are using a self-hosted GitLab instance with no SSL certificate or having
**`gitlab.remoteName`** _(required: false, default: null)_
The name of the git remote link corresponding to the Gitlab repositiory with your MR and issues. If no setting is provided, the extension will detect it. For example: origin.
The name of the git remote link corresponding to the GitLab repositiory with your MR and issues. If no setting is provided, the extension will detect it. For example: origin.
**`gitlab.pipelineGitRemoteName`** _(required: false, default: null)_
The name of the git remote link corresponding to the GitLab repositiory with your pipelines. If no setting is provided, the extension will detect it. For example: origin.
## Usage
- Open up Command Palette by pressing `Cmd+Shift+P`.
......
......@@ -189,6 +189,11 @@
"default": null,
"description": "Name of the git remote to use in order to locate the Gitlab project"
},
"gitlab.pipelineGitRemoteName": {
"type": "string",
"default": null,
"description": "Name of the git remote to use in order to locate the Gitlab project for your pipeline. Keep empty for default"
},
"gitlab.showPipelineUpdateNotifications": {
"type": "boolean",
"default": false,
......
......@@ -80,12 +80,12 @@ const parseGitRemote = remote => {
return [protocol, hostname, ...match.slice(1, 3)];
};
async function fetchGitRemote() {
async function fetchRemoteUrl(name) {
let remoteUrl = null;
let remoteName = name;
try {
const branchName = await fetchBranchName();
let { remoteName } = vscode.workspace.getConfiguration('gitlab');
if (!remoteName) {
remoteName = await fetch(`git config --get branch.${branchName}.remote`);
}
......@@ -109,7 +109,20 @@ async function fetchGitRemote() {
return null;
}
async function fetchGitRemote() {
const { remoteName } = vscode.workspace.getConfiguration('gitlab');
return await fetchRemoteUrl(remoteName);
}
async function fetchGitRemotePipeline() {
const { pipelineGitRemoteName } = vscode.workspace.getConfiguration('gitlab');
return await fetchRemoteUrl(pipelineGitRemoteName);
}
exports.fetchBranchName = fetchBranchName;
exports.fetchTrackingBranchName = fetchTrackingBranchName;
exports.fetchLastCommitId = fetchLastCommitId;
exports.fetchGitRemote = fetchGitRemote;
exports.fetchGitRemotePipeline = fetchGitRemotePipeline;
......@@ -57,9 +57,7 @@ async function fetch(path, method = 'GET', data = null) {
}
}
async function fetchCurrentProject() {
const remote = await gitService.fetchGitRemote();
async function fetchProjectData(remote) {
if (remote) {
const { namespace, project } = remote;
const projectData = await fetch(`/projects/${namespace.replace(/\//g, '%2F')}%2F${project}`);
......@@ -70,6 +68,30 @@ async function fetchCurrentProject() {
return null;
}
async function fetchCurrentProject() {
try {
const remote = await gitService.fetchGitRemote();
return await fetchProjectData(remote);
} catch (e) {
console.log('Failed to execute fetch', e);
return null;
}
}
async function fetchCurrentPipelineProject() {
try {
const remote = await gitService.fetchGitRemotePipeline();
return await fetchProjectData(remote);
} catch (e) {
console.log('Failed to execute fetch', e);
return null;
}
}
async function fetchUser(userName) {
let user = null;
......@@ -154,7 +176,7 @@ async function fetchMyOpenMergeRequests() {
}
async function fetchLastPipelineForCurrentBranch() {
const project = await fetchCurrentProject();
const project = await fetchCurrentPipelineProject();
let pipeline = null;
if (project) {
......@@ -300,6 +322,7 @@ exports.fetchMyOpenMergeRequests = fetchMyOpenMergeRequests;
exports.fetchOpenMergeRequestForCurrentBranch = fetchOpenMergeRequestForCurrentBranch;
exports.fetchLastPipelineForCurrentBranch = fetchLastPipelineForCurrentBranch;
exports.fetchCurrentProject = fetchCurrentProject;
exports.fetchCurrentPipelineProject = fetchCurrentPipelineProject;
exports.handlePipelineAction = handlePipelineAction;
exports.fetchMRIssues = fetchMRIssues;
exports.createSnippet = createSnippet;
......
......@@ -111,7 +111,7 @@ async function openProjectPage() {
}
async function openCurrentPipeline() {
const project = await gitLabService.fetchCurrentProject();
const project = await gitLabService.fetchCurrentPipelineProject();
if (project) {
const pipeline = await gitLabService.fetchLastPipelineForCurrentBranch();
......
......@@ -48,7 +48,7 @@ async function refreshPipeline() {
};
try {
project = await gitLabService.fetchCurrentProject();
project = await gitLabService.fetchCurrentPipelineProject();
pipeline = await gitLabService.fetchLastPipelineForCurrentBranch();
} catch (e) {
if (!project) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册