-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import type {Command} from "commander"; | ||
import {newAxiosInstance, resolvePluginConfig} from "./plugin.js"; | ||
import urlJoin from "url-join"; | ||
import {AxiosError, type AxiosResponse} from "axios"; | ||
|
||
export function addListCommand(command: Command): void { | ||
command | ||
.command('list') | ||
.description('get merge request') | ||
.option('--project-id [projectId]', 'Project id') | ||
.option('--gitlab-url [gitlabUrl]', 'Gitlab url') | ||
.option('--source-branch <sourceBranch>', 'Source branch') | ||
.action(listAction); | ||
} | ||
|
||
interface ListOptions { | ||
projectId?: string; | ||
gitlabUrl?: string; | ||
sourceBranch: string; | ||
} | ||
|
||
export async function listAction(options: ListOptions) { | ||
const fakeContext = {env: process.env, cwd: process.cwd()} as any; | ||
const config = resolvePluginConfig({projectId: options.projectId, gitlabUrl: options.gitlabUrl}, fakeContext); | ||
const instance = newAxiosInstance(config); | ||
|
||
const response: AxiosResponse | AxiosError = await instance.get(urlJoin(config.gitlabBaseUrl, 'merge_requests'), { | ||
params: { | ||
source_branch: options.sourceBranch, | ||
} | ||
}); | ||
if (response instanceof AxiosError) { | ||
throw response; | ||
} | ||
if (response.status !== 200) { | ||
console.error(`Failed to create merge request: ${JSON.stringify(response.data)}, Status ${response.status}`); | ||
throw new Error(`Failed to accept merge request`); | ||
} | ||
console.log(JSON.stringify(response.data)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters