mirror of
https://github.com/matrix-org/matrix-hookshot.git
synced 2025-03-10 21:19:13 +00:00
Add support for creating confidential issues in GitLab (#496)
* Confidential issue * changelog * Dedupe a bit
This commit is contained in:
parent
01750bf6f2
commit
f9e3554e0e
1
changelog.d/496.feature
Normal file
1
changelog.d/496.feature
Normal file
@ -0,0 +1 @@
|
|||||||
|
Added `create-confidential` GitLab connection command.
|
@ -14,6 +14,7 @@ import { GetConnectionsResponseItem } from "../provisioning/api";
|
|||||||
import { ErrCode, ApiError, ValidatorApiError } from "../api"
|
import { ErrCode, ApiError, ValidatorApiError } from "../api"
|
||||||
import { AccessLevel } from "../Gitlab/Types";
|
import { AccessLevel } from "../Gitlab/Types";
|
||||||
import Ajv, { JSONSchemaType } from "ajv";
|
import Ajv, { JSONSchemaType } from "ajv";
|
||||||
|
import { CommandError } from "../errors";
|
||||||
|
|
||||||
export interface GitLabRepoConnectionState extends IConnectionState {
|
export interface GitLabRepoConnectionState extends IConnectionState {
|
||||||
instance: string;
|
instance: string;
|
||||||
@ -328,13 +329,17 @@ export class GitLabRepoConnection extends CommandConnection<GitLabRepoConnection
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@botCommand("create", "Create an issue for this repo", ["title"], ["description", "labels"], true)
|
private async getClientForUser(userId: string) {
|
||||||
public async onCreateIssue(userId: string, title: string, description?: string, labels?: string) {
|
|
||||||
const client = await this.tokenStore.getGitLabForUser(userId, this.instance.url);
|
const client = await this.tokenStore.getGitLabForUser(userId, this.instance.url);
|
||||||
if (!client) {
|
if (!client) {
|
||||||
await this.as.botIntent.sendText(this.roomId, "You must be logged in to create an issue.", "m.notice");
|
throw new CommandError('User is not logged into GitLab', 'You must be logged in to create an issue.');
|
||||||
throw Error('Not logged in');
|
|
||||||
}
|
}
|
||||||
|
return client;
|
||||||
|
}
|
||||||
|
|
||||||
|
@botCommand("create", "Create an issue for this repo", ["title"], ["description", "labels"], true)
|
||||||
|
public async onCreateIssue(userId: string, title: string, description?: string, labels?: string) {
|
||||||
|
const client = await this.getClientForUser(userId);
|
||||||
const res = await client.issues.create({
|
const res = await client.issues.create({
|
||||||
id: this.path,
|
id: this.path,
|
||||||
title,
|
title,
|
||||||
@ -351,13 +356,29 @@ export class GitLabRepoConnection extends CommandConnection<GitLabRepoConnection
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@botCommand("create-confidential", "Create a confidental issue for this repo", ["title"], ["description", "labels"], true)
|
||||||
|
public async onCreateConfidentialIssue(userId: string, title: string, description?: string, labels?: string) {
|
||||||
|
const client = await this.getClientForUser(userId);
|
||||||
|
const res = await client.issues.create({
|
||||||
|
id: this.path,
|
||||||
|
title,
|
||||||
|
description,
|
||||||
|
confidential: true,
|
||||||
|
labels: labels ? labels.split(",") : undefined,
|
||||||
|
});
|
||||||
|
|
||||||
|
const content = `Created confidential issue #${res.iid}: [${res.web_url}](${res.web_url})`;
|
||||||
|
return this.as.botIntent.sendEvent(this.roomId,{
|
||||||
|
msgtype: "m.notice",
|
||||||
|
body: content,
|
||||||
|
formatted_body: md.render(content),
|
||||||
|
format: "org.matrix.custom.html"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@botCommand("close", "Close an issue", ["number"], ["comment"], true)
|
@botCommand("close", "Close an issue", ["number"], ["comment"], true)
|
||||||
public async onClose(userId: string, number: string) {
|
public async onClose(userId: string, number: string) {
|
||||||
const client = await this.tokenStore.getGitLabForUser(userId, this.instance.url);
|
const client = await this.getClientForUser(userId);
|
||||||
if (!client) {
|
|
||||||
await this.as.botIntent.sendText(this.roomId, "You must be logged in to create an issue.", "m.notice");
|
|
||||||
throw Error('Not logged in');
|
|
||||||
}
|
|
||||||
|
|
||||||
await client.issues.edit({
|
await client.issues.edit({
|
||||||
id: this.state.path,
|
id: this.state.path,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user