Compare commits
7 Commits
Author | SHA1 | Date | |
---|---|---|---|
cc00a78e2c | |||
cf7e69e74a | |||
5cc3aeb27c | |||
098a9c64c6 | |||
1fd2bb8e01 | |||
ca475fbfab | |||
c8dc59cdf2 |
20047
package-lock.json
generated
20047
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
11
package.json
11
package.json
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@mojoio/gitlab",
|
"name": "@mojoio/gitlab",
|
||||||
"version": "1.0.6",
|
"version": "1.0.10",
|
||||||
"description": "api abstraction package for gitlab",
|
"description": "api abstraction package for gitlab",
|
||||||
"main": "dist_ts/index.js",
|
"main": "dist_ts/index.js",
|
||||||
"typings": "dist_ts/index.d.ts",
|
"typings": "dist_ts/index.d.ts",
|
||||||
@ -11,9 +11,9 @@
|
|||||||
"build": "(tsbuild --web)"
|
"build": "(tsbuild --web)"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsbuild": "^2.1.25",
|
"@gitzone/tsbuild": "^2.1.27",
|
||||||
"@gitzone/tsrun": "^1.2.12",
|
"@gitzone/tsrun": "^1.2.17",
|
||||||
"@gitzone/tstest": "^1.0.54",
|
"@gitzone/tstest": "^1.0.57",
|
||||||
"@pushrocks/tapbundle": "^3.2.14",
|
"@pushrocks/tapbundle": "^3.2.14",
|
||||||
"tslint": "^6.1.3",
|
"tslint": "^6.1.3",
|
||||||
"tslint-config-prettier": "^1.18.0"
|
"tslint-config-prettier": "^1.18.0"
|
||||||
@ -21,7 +21,8 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pushrocks/smartfile": "^8.0.10",
|
"@pushrocks/smartfile": "^8.0.10",
|
||||||
"@pushrocks/smartrequest": "^1.1.52",
|
"@pushrocks/smartrequest": "^1.1.52",
|
||||||
"@pushrocks/smarturl": "^2.0.1"
|
"@pushrocks/smarturl": "^2.0.1",
|
||||||
|
"@tsclass/tsclass": "^3.0.34"
|
||||||
},
|
},
|
||||||
"private": false,
|
"private": false,
|
||||||
"browserslist": [
|
"browserslist": [
|
||||||
|
@ -34,7 +34,6 @@ For further information read the linked docs at the top of this README.
|
|||||||
|
|
||||||
[](https://mojo.io)
|
[](https://mojo.io)
|
||||||
|
|
||||||
|
|
||||||
## Contribution
|
## Contribution
|
||||||
|
|
||||||
We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can [contribute one time](https://lossless.link/contribute-onetime) or [contribute monthly](https://lossless.link/contribute). :)
|
We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can [contribute one time](https://lossless.link/contribute-onetime) or [contribute monthly](https://lossless.link/contribute). :)
|
||||||
|
18
test/test.ts
18
test/test.ts
@ -3,24 +3,24 @@ import * as gitlab from '../ts/index';
|
|||||||
|
|
||||||
let testGitlabAccount: gitlab.GitlabAccount;
|
let testGitlabAccount: gitlab.GitlabAccount;
|
||||||
|
|
||||||
tap.test('should create an anonymous Gitlab Account', async () => {
|
const test1 = tap.test('should create an anonymous Gitlab Account', async () => {
|
||||||
testGitlabAccount = gitlab.GitlabAccount.createAnonymousAccount();
|
testGitlabAccount = gitlab.GitlabAccount.createAnonymousAccount();
|
||||||
expect(testGitlabAccount).to.be.instanceOf(gitlab.GitlabAccount);
|
expect(testGitlabAccount).to.be.instanceOf(gitlab.GitlabAccount);
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should get the pushrocks group', async () => {
|
const test2 = tap.test('should get the pushrocks group', async () => {
|
||||||
const pushrocksGroup = await testGitlabAccount.getGroupByName('pushrocks');
|
const pushrocksGroup = await testGitlabAccount.getGroupByName('pushrocks');
|
||||||
expect(pushrocksGroup).to.be.instanceOf(gitlab.GitlabGroup);
|
expect(pushrocksGroup).to.be.instanceOf(gitlab.GitlabGroup);
|
||||||
console.log(pushrocksGroup);
|
console.log(pushrocksGroup);
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should get the pushrocks group', async () => {
|
const test3 = tap.test('should get the pushrocks group', async () => {
|
||||||
const pushrocksGroup = await testGitlabAccount.getGroupByName('pushrocks');
|
const pushrocksGroup = await testGitlabAccount.getGroupByName('pushrocks');
|
||||||
expect(pushrocksGroup).to.be.instanceOf(gitlab.GitlabGroup);
|
expect(pushrocksGroup).to.be.instanceOf(gitlab.GitlabGroup);
|
||||||
await pushrocksGroup.getProjects();
|
await pushrocksGroup.getProjects();
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should get the readme of a project', async () => {
|
const test4 = tap.test('should get the readme of a project', async () => {
|
||||||
const pushrocksGroup = await testGitlabAccount.getGroupByName('pushrocks');
|
const pushrocksGroup = await testGitlabAccount.getGroupByName('pushrocks');
|
||||||
expect(pushrocksGroup).to.be.instanceOf(gitlab.GitlabGroup);
|
expect(pushrocksGroup).to.be.instanceOf(gitlab.GitlabGroup);
|
||||||
const projects = await pushrocksGroup.getProjects();
|
const projects = await pushrocksGroup.getProjects();
|
||||||
@ -29,7 +29,15 @@ tap.test('should get the readme of a project', async () => {
|
|||||||
});
|
});
|
||||||
expect(selectedProject.data.name).to.equal('smartfile');
|
expect(selectedProject.data.name).to.equal('smartfile');
|
||||||
const readme = await selectedProject.getReadmeAsMarkdown('master');
|
const readme = await selectedProject.getReadmeAsMarkdown('master');
|
||||||
expect(readme).to.startWith('# @pushrocks/smartfile');
|
expect(readme.startsWith('# @pushrocks/smartfile')).to.be.true;
|
||||||
|
return projects;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const test5 = tap.test('should be able to create an article list', async () => {
|
||||||
|
const projects: gitlab.GitlabProject[] = (await test4.testResultPromise) as any;
|
||||||
|
for (const project of projects) {
|
||||||
|
console.log(await project.getProjectAsArticle());
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
tap.start();
|
tap.start();
|
||||||
|
@ -33,7 +33,7 @@ export class GitlabAccount {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// lets deal with pagination headers
|
// lets deal with pagination headers
|
||||||
const findLinkName = (markup) => {
|
const findLinkName = (markup: string) => {
|
||||||
const pattern = /<([^\s>]+)(\s|>)+/;
|
const pattern = /<([^\s>]+)(\s|>)+/;
|
||||||
return markup.match(pattern)[1];
|
return markup.match(pattern)[1];
|
||||||
};
|
};
|
||||||
@ -46,12 +46,16 @@ export class GitlabAccount {
|
|||||||
for (const link of links) {
|
for (const link of links) {
|
||||||
linkObjects.push({
|
linkObjects.push({
|
||||||
original: link,
|
original: link,
|
||||||
link: findLinkName(link)
|
link: findLinkName(link),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
const next = linkObjects.find(linkObject => linkObject.original.includes('rel="next"'));
|
const next = linkObjects.find((linkObject) => linkObject.original.includes('rel="next"'));
|
||||||
if (next && response.body instanceof Array) {
|
if (next && response.body instanceof Array) {
|
||||||
const nextResponse = await this.request(methodArg, next.link.replace('https://gitlab.com/api/v4', ''), {});
|
const nextResponse = await this.request(
|
||||||
|
methodArg,
|
||||||
|
next.link.replace('https://gitlab.com/api/v4', ''),
|
||||||
|
{}
|
||||||
|
);
|
||||||
response.body = response.body.concat(nextResponse);
|
response.body = response.body.concat(nextResponse);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -111,7 +111,7 @@ export class GitlabProject {
|
|||||||
per_page: '100',
|
per_page: '100',
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
const allProjects: GitlabProject[] = []
|
const allProjects: GitlabProject[] = [];
|
||||||
for (const projectData of response) {
|
for (const projectData of response) {
|
||||||
allProjects.push(new GitlabProject(projectData, gitlabGroupArg));
|
allProjects.push(new GitlabProject(projectData, gitlabGroupArg));
|
||||||
}
|
}
|
||||||
@ -127,15 +127,47 @@ export class GitlabProject {
|
|||||||
this.gitlabGroupRef = gitlabGroupRefArg;
|
this.gitlabGroupRef = gitlabGroupRefArg;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getFileFromProject(filePathArg: string, refArg: string): Promise<plugins.smartfile.Smartfile> {
|
public async getFileFromProject(
|
||||||
const response = await this.gitlabGroupRef.gitlabAccountRef.request('GET', `/projects/${this.data.id}/repository/files/${filePathArg}`, {
|
filePathArg: string,
|
||||||
ref: refArg
|
refArg: string
|
||||||
});
|
): Promise<plugins.smartfile.Smartfile> {
|
||||||
return plugins.smartfile.Smartfile.fromBuffer(filePathArg, Buffer.from(response.content, response.encoding));
|
const response = await this.gitlabGroupRef.gitlabAccountRef.request(
|
||||||
|
'GET',
|
||||||
|
`/projects/${this.data.id}/repository/files/${filePathArg}`,
|
||||||
|
{
|
||||||
|
ref: refArg,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
return plugins.smartfile.Smartfile.fromBuffer(
|
||||||
|
filePathArg,
|
||||||
|
Buffer.from(response.content, response.encoding)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getReadmeAsMarkdown(refArg: string = 'master'): Promise<string> {
|
public async getReadmeAsMarkdown(refArg: string = 'master'): Promise<string> {
|
||||||
const readmeFile = await this.getFileFromProject('readme.md', refArg);
|
const readmeFile = await this.getFileFromProject('readme.md', refArg);
|
||||||
return readmeFile.contents.toString('utf8');
|
return readmeFile.contents.toString('utf8');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async getNpmKeywords(refArg: string = 'master'): Promise<string[]> {
|
||||||
|
const packageJsonFile = await this.getFileFromProject('package.json', refArg);
|
||||||
|
const packageJsonObject: any = JSON.parse(packageJsonFile.contents.toString('utf8'));
|
||||||
|
return packageJsonObject.keywords ? packageJsonObject.keywords : [];
|
||||||
|
}
|
||||||
|
|
||||||
|
public async getProjectAsArticle(): Promise<plugins.tsclass.content.IArticle> {
|
||||||
|
return {
|
||||||
|
url: this.data.web_url,
|
||||||
|
author: null,
|
||||||
|
content: await this.getReadmeAsMarkdown().catch(err => null),
|
||||||
|
tags: await this.getNpmKeywords().catch(err => null),
|
||||||
|
title: this.data.name,
|
||||||
|
timestamp: new Date(this.data.last_activity_at).getTime(),
|
||||||
|
featuredImageUrl: null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async syncNpmKeywordsToGitlabTopics() {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,10 @@
|
|||||||
|
// @tsclass scope
|
||||||
|
import * as tsclass from '@tsclass/tsclass';
|
||||||
|
|
||||||
|
export {
|
||||||
|
tsclass
|
||||||
|
}
|
||||||
|
|
||||||
// pushrocks scope
|
// pushrocks scope
|
||||||
import * as smartfile from '@pushrocks/smartfile';
|
import * as smartfile from '@pushrocks/smartfile';
|
||||||
import * as smartrequest from '@pushrocks/smartrequest';
|
import * as smartrequest from '@pushrocks/smartrequest';
|
||||||
|
@ -1,2 +1,3 @@
|
|||||||
export * from './gitlab.classes.group';
|
export * from './gitlab.classes.group';
|
||||||
export * from './gitlab.classes.account';
|
export * from './gitlab.classes.account';
|
||||||
|
export * from './gitlab.classes.project';
|
Loading…
x
Reference in New Issue
Block a user