Compare commits

...

1 Commits

Author SHA1 Message Date
Ali BARIN
69ae448d64 feat: new find project merge requests action in GitLab 2022-05-07 20:47:37 +02:00
8 changed files with 177 additions and 2 deletions

View File

@@ -0,0 +1,13 @@
import { IJSONObject } from '@automatisch/types';
import FindProjectMergeRequests from './actions/find-project-merge-requests';
export default class Actions {
findProjectMergeRequests: FindProjectMergeRequests;
constructor(connectionData: IJSONObject, parameters: IJSONObject) {
this.findProjectMergeRequests = new FindProjectMergeRequests(
connectionData,
parameters
);
}
}

View File

@@ -0,0 +1,35 @@
import { Gitlab } from '@gitbeaker/node';
import { IJSONObject } from '@automatisch/types';
export default class FindProjectMergeRequests {
client: any;
projectId: number;
state: string;
constructor(connectionData: IJSONObject, parameters: IJSONObject) {
if (connectionData?.accessToken) {
this.client = new Gitlab({
host: `https://${connectionData.host}`,
oauthToken: connectionData?.accessToken as string,
});
}
if (parameters.project) {
this.projectId = parameters.project as number;
}
if (parameters.state) {
this.state = parameters.state as string;
}
}
async run() {
const mergeRequests = await this.client.MergeRequests.all({
state: this.state,
projectId: this.projectId,
maxPages: 1,
});
return { data: mergeRequests };
}
}

View File

@@ -0,0 +1,10 @@
import { IJSONObject } from '@automatisch/types';
import ListProjects from './data/list-projects';
export default class Data {
listProjects: ListProjects;
constructor(connectionData: IJSONObject, parameters?: IJSONObject) {
this.listProjects = new ListProjects(connectionData, parameters);
}
}

View File

@@ -0,0 +1,26 @@
import { Gitlab } from '@gitbeaker/node';
import type { IJSONObject } from '@automatisch/types';
export default class ListProjects {
client?: any;
constructor(connectionData: IJSONObject, parameters?: IJSONObject) {
if (connectionData?.accessToken) {
this.client = new Gitlab({
host: `https://${connectionData.host}`,
oauthToken: connectionData?.accessToken as string,
});
}
}
async run() {
const projects = await this.client.Projects.all({
membership: true,
});
return projects.map((project: any) => ({
value: project.id,
name: project.name_with_namespace,
}));
}
}

View File

@@ -1,15 +1,25 @@
import Authentication from './authentication';
import {
IService,
IAuthentication,
IApp,
IJSONObject,
} from '@automatisch/types';
import Authentication from './authentication';
import Actions from './actions';
import Data from './data';
export default class Gitlab implements IService {
authenticationClient: IAuthentication;
actions: Actions;
data: Data;
constructor(appData: IApp, connectionData: IJSONObject) {
constructor(
appData: IApp,
connectionData: IJSONObject,
parameters: IJSONObject
) {
this.authenticationClient = new Authentication(appData, connectionData);
this.actions = new Actions(connectionData, parameters);
this.data = new Data(connectionData, parameters);
}
}

View File

@@ -234,5 +234,76 @@
}
]
}
],
"actions": [
{
"name": "Find project merge requests",
"key": "findProjectMergeRequests",
"description": "Find merge requests for a project.",
"substeps": [
{
"key": "chooseAccount",
"name": "Choose account"
},
{
"key": "setupAction",
"name": "Set up action",
"arguments": [
{
"label": "Project",
"key": "project",
"type": "dropdown",
"required": true,
"description": "Search for merge requests in this project.",
"variables": false,
"source": {
"type": "query",
"name": "getData",
"arguments": [
{
"name": "key",
"value": "listProjects"
}
]
}
},
{
"label": "State",
"key": "state",
"type": "dropdown",
"required": true,
"description": "Filter merge requests by their state.",
"variables": false,
"options": [
{
"label": "All",
"value": "all"
},
{
"label": "Opened",
"value": "opened"
},
{
"label": "Closed",
"value": "closed"
},
{
"label": "Locked",
"value": "locked"
},
{
"label": "Merged",
"value": "merged"
}
]
}
]
},
{
"key": "testStep",
"name": "Test action"
}
]
}
]
}

View File

@@ -68,6 +68,7 @@ type ActionSubstepArgument {
variables: Boolean
source: ActionSubstepArgumentSource
dependsOn: [String]
options: [TriggerSubstepArgumentOption]
}
type ActionSubstepArgumentSource {
@@ -76,6 +77,11 @@ type ActionSubstepArgumentSource {
arguments: [ActionSubstepArgumentSourceArgument]
}
type TriggerSubstepArgumentOption {
label: String
value: JSONObject
}
type ActionSubstepArgumentSourceArgument {
name: String
value: String

View File

@@ -94,6 +94,10 @@ export const GET_APPS = gql`
description
variables
dependsOn
options {
label
value
}
source {
type
name