diff --git a/CHANGELOG.md b/CHANGELOG.md index fb9b091f427831a3ed3c9174af4fc69c32288a3d..8614e58ac006c85c004adc1fe23aa95c90fb4115 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,18 @@ -# Change Log -All notable changes to the "gitlab-workflow" extension will be documented in this file. +# CHANGELOG -Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file. +## [0.2.0] - 2018-01-27 +### Added +- Added a new service layer to opearate git commands. +- Added a new service layer to talk with GitLab API. +- Added new methods to get info from Git and GitLab. +- Implemented MR link on status bar. +- Implemented pipeline status on status bar. +- Implemented UI flow to ask and store GitLab Personal Access Token. -## [Unreleased] -- Initial release \ No newline at end of file +### Changed +- Removed `gitlab.userId` necessity. + +## [0.1.1] - 2018-01-25 +### Added +- Implemented show issues assinged to me. +- Implemented show merge requests assinged to me. diff --git a/src/gitlab_service.js b/src/gitlab_service.js index 1cff86ea6a820434ae535a6be4b3d7146f0f81da..53b81f1e3369cb69b899d5668e1d53c36ff03a04 100644 --- a/src/gitlab_service.js +++ b/src/gitlab_service.js @@ -6,7 +6,7 @@ async function fetch(path) { const config = { url: `${apiRoot}${path}`, headers: { - 'PRIVATE-TOKEN': 'TOKEN', // FIXME + 'PRIVATE-TOKEN': 'f9vX_GfmWc_SLzz7Siaq', // FIXME: Make token UI } }; @@ -19,15 +19,21 @@ async function fetch(path) { } } -// FIXME: Don't rely created-by-me -// FIXME: Fix project id +// FIXME: Don't rely on `created-by-me`. It doesn't have to be my own MR. +// Currently GL API doesn't support finding MR by branch name or commit id. async function fetchMyOpenMergeRequests() { - return await fetch('/projects/13083/merge_requests?scope=created-by-me&state=opened'); + const project = await fetchCurrentProject(); + + if (project) { + return await fetch(`/projects/${project.id}/merge_requests?scope=created-by-me&state=opened`); + } + + return null; } async function fetchOpenMergeRequestForCurrentBranch() { const branchName = await gitService.fetchBranchName(); - const mrs = await fetchMyOpenMergeRequests(); // FIXME: I doesn't have to be my MR + const mrs = await fetchMyOpenMergeRequests(); return mrs.filter(mr => mr.source_branch === branchName)[0]; } @@ -50,6 +56,20 @@ async function fetchLastPipelineForCurrentBranch() { return null; } +async function fetchCurrentProject() { + const remote = await gitService.fetchGitRemote(); + + if (remote) { + const { namespace, project } = remote; + const projectData = await fetch(`/projects/${namespace}%2F${project}`); + + return projectData || null; + } + + return null; +} + exports.fetchMyOpenMergeRequests = fetchMyOpenMergeRequests; exports.fetchOpenMergeRequestForCurrentBranch = fetchOpenMergeRequestForCurrentBranch; exports.fetchLastPipelineForCurrentBranch = fetchLastPipelineForCurrentBranch; +exports.fetchCurrentProject = fetchCurrentProject;