fix(core): update
This commit is contained in:
43
ts/gitlab.classes.account.ts
Normal file
43
ts/gitlab.classes.account.ts
Normal file
@ -0,0 +1,43 @@
|
||||
import { GitlabGroup } from './gitlab.classes.group';
|
||||
import * as plugins from './gitlab.plugins';
|
||||
|
||||
export class GitlabAccount {
|
||||
public static createAnonymousAccount() {
|
||||
return new GitlabAccount();
|
||||
}
|
||||
|
||||
// INSTANCE
|
||||
public async getGroupByName(nameArg: string): Promise<GitlabGroup> {
|
||||
return GitlabGroup.getByName(nameArg, this);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* handles the basic request/response patterns with the gitlab.com API
|
||||
*/
|
||||
public async request (methodArg: 'GET' | 'POST', routeArg: string, searchParamsArg: {[key: string]: string}) {
|
||||
if(!routeArg.startsWith('/')) {
|
||||
throw new Error(`"${routeArg}" -> routeArg must start with a slash`);
|
||||
}
|
||||
const smarturlInstance = plugins.smarturl.Smarturl.createFromUrl(`https://gitlab.com/api/v4${routeArg}`, {
|
||||
searchParams: searchParamsArg
|
||||
});
|
||||
const response = await plugins.smartrequest.request(smarturlInstance.toString(), {
|
||||
method: methodArg
|
||||
});
|
||||
|
||||
// lets deal with pagination headers
|
||||
const fintLinkName = (markup) => {
|
||||
const pattern = /<([^\s>]+)(\s|>)+/;
|
||||
return markup.match(pattern)[1];
|
||||
};
|
||||
if (typeof response.headers.link === 'string') {
|
||||
const links = response.headers.link.split(',');
|
||||
const linkObjects: {
|
||||
original: string;
|
||||
link: string;
|
||||
}[] = [];
|
||||
}
|
||||
return response.body;
|
||||
}
|
||||
}
|
54
ts/gitlab.classes.group.ts
Normal file
54
ts/gitlab.classes.group.ts
Normal file
@ -0,0 +1,54 @@
|
||||
import * as plugins from './gitlab.plugins';
|
||||
import { GitlabAccount } from './gitlab.classes.account';
|
||||
import { GitlabProject } from './gitlab.classes.project';
|
||||
|
||||
export interface IGitlabGroup {
|
||||
id: number;
|
||||
web_url: string;
|
||||
name: string;
|
||||
path: string;
|
||||
description: string;
|
||||
visibility: string;
|
||||
share_with_group_lock: string;
|
||||
require_two_factor_authentication: string;
|
||||
two_factor_grace_period: number;
|
||||
project_creation_level: string;
|
||||
auto_devops_enabled: null;
|
||||
subgroup_creation_level: string;
|
||||
emails_disabled: null;
|
||||
mentions_disabled: null;
|
||||
lfs_enabled: boolean;
|
||||
default_branch_protection: number;
|
||||
avatar_url: string;
|
||||
request_access_enabled: boolean;
|
||||
full_name: string;
|
||||
full_path: string;
|
||||
created_at: string;
|
||||
parent_id: null;
|
||||
ldap_cn: null;
|
||||
ldap_access: null;
|
||||
}
|
||||
|
||||
export class GitlabGroup {
|
||||
public static async getByName(nameArg: string, gitlabAccountArg: GitlabAccount) {
|
||||
const response = await gitlabAccountArg.request('GET', '/groups', {
|
||||
search: 'pushrocks',
|
||||
});
|
||||
// console.log(response);
|
||||
const returnGroup = new GitlabGroup(response[0], gitlabAccountArg);
|
||||
return returnGroup;
|
||||
}
|
||||
|
||||
// INSTANCE
|
||||
public gitlabAccountRef: GitlabAccount;
|
||||
public data: IGitlabGroup;
|
||||
|
||||
constructor(dataArg: IGitlabGroup, gitlabAccountArg: GitlabAccount) {
|
||||
this.gitlabAccountRef = gitlabAccountArg;
|
||||
this.data = dataArg;
|
||||
}
|
||||
|
||||
public async getProjects() {
|
||||
return GitlabProject.getProjectsForGroup(this);
|
||||
}
|
||||
}
|
27
ts/gitlab.classes.project.ts
Normal file
27
ts/gitlab.classes.project.ts
Normal file
@ -0,0 +1,27 @@
|
||||
import { GitlabGroup } from './gitlab.classes.group';
|
||||
import * as plugins from './gitlab.plugins';
|
||||
|
||||
export class GitlabProject {
|
||||
// STATIC
|
||||
public static async getProjectsForGroup(gitlabGroupArg: GitlabGroup) {
|
||||
const response = await gitlabGroupArg.gitlabAccountRef.request('GET', `/groups/${gitlabGroupArg.data.id}/projects`, {
|
||||
per_page: '100'
|
||||
});
|
||||
console.log(response);
|
||||
for (const projectData of response) {
|
||||
console.log(projectData);
|
||||
}
|
||||
console.log(response.length);
|
||||
}
|
||||
|
||||
// INSTANCE
|
||||
gitlabGroupRef: GitlabGroup;
|
||||
data: any;
|
||||
|
||||
constructor(dataArg: any, gitlabGroupRefArg: GitlabGroup) {
|
||||
this.data = dataArg;
|
||||
this.gitlabGroupRef = gitlabGroupRefArg;
|
||||
}
|
||||
|
||||
public async getReadmeAsMarkdown() {};
|
||||
}
|
8
ts/gitlab.plugins.ts
Normal file
8
ts/gitlab.plugins.ts
Normal file
@ -0,0 +1,8 @@
|
||||
// pushrocks scope
|
||||
import * as smartrequest from '@pushrocks/smartrequest';
|
||||
import * as smarturl from '@pushrocks/smarturl';
|
||||
|
||||
export {
|
||||
smartrequest,
|
||||
smarturl
|
||||
};
|
@ -1 +0,0 @@
|
||||
import 'typings-global'
|
@ -1,5 +0,0 @@
|
||||
import * as plugins from './glab.plugins'
|
||||
|
||||
export class GlabTrigger {
|
||||
// TODO:
|
||||
}
|
@ -1,3 +1,2 @@
|
||||
import * as plugins from './glab.plugins'
|
||||
|
||||
export * from './glab.trigger'
|
||||
export * from './gitlab.classes.group';
|
||||
export * from './gitlab.classes.account';
|
||||
|
Reference in New Issue
Block a user