Compare commits

..

No commits in common. "master" and "v1.0.4" have entirely different histories.

13 changed files with 2981 additions and 17682 deletions

18
.gitignore vendored
View File

@ -1,20 +1,4 @@
.nogit/ node_modules/
# artifacts
coverage/ coverage/
public/ public/
pages/ pages/
# installs
node_modules/
# caches
.yarn/
.cache/
.rpt2_cache
# builds
dist/
dist_*/
# custom

View File

@ -1,76 +1,38 @@
# gitzone ci_default # gitzone standard
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci image: hosttoday/ht-docker-node:npmci
cache: cache:
paths: paths:
- .npmci_cache/ - .yarn/
key: '$CI_BUILD_STAGE' key: "$CI_BUILD_STAGE"
stages: stages:
- security - test
- test - release
- release - trigger
- metadata - pages
# ==================== testLEGACY:
# security stage stage: test
# ====================
mirror:
stage: security
script: script:
- npmci git mirror - npmci test legacy
only: coverage: /\d+.?\d+?\%\s*coverage/
- tags
tags:
- lossless
- docker
- notpriv
auditProductionDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security
script:
- npmci npm prepare
- npmci command npm install --production --ignore-scripts
- npmci command npm config set registry https://registry.npmjs.org
- npmci command npm audit --audit-level=high --only=prod --production
tags:
- docker
auditDevDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security
script:
- npmci npm prepare
- npmci command npm install --ignore-scripts
- npmci command npm config set registry https://registry.npmjs.org
- npmci command npm audit --audit-level=high --only=dev
tags: tags:
- docker - docker
allow_failure: true allow_failure: true
# ==================== testLTS:
# test stage
# ====================
testStable:
stage: test stage: test
script: script:
- npmci npm prepare - npmci test lts
- npmci node install stable
- npmci npm install
- npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/ coverage: /\d+.?\d+?\%\s*coverage/
tags: tags:
- docker - docker
testBuild: testSTABLE:
stage: test stage: test
script: script:
- npmci npm prepare - npmci test stable
- npmci node install stable
- npmci npm install
- npmci command npm run build
coverage: /\d+.?\d+?\%\s*coverage/ coverage: /\d+.?\d+?\%\s*coverage/
tags: tags:
- docker - docker
@ -78,60 +40,32 @@ testBuild:
release: release:
stage: release stage: release
script: script:
- npmci node install stable - npmci publish
- npmci npm publish
only: only:
- tags - tags
tags: tags:
- lossless
- docker - docker
- notpriv
# ====================
# metadata stage
# ====================
codequality:
stage: metadata
allow_failure: true
only:
- tags
script:
- npmci command npm install -g tslint typescript
- npmci npm prepare
- npmci npm install
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
tags:
- lossless
- docker
- priv
trigger: trigger:
stage: metadata stage: trigger
script: script:
- npmci trigger - npmci trigger
only: only:
- tags - tags
tags: tags:
- lossless
- docker - docker
- notpriv
pages: pages:
stage: metadata image: hosttoday/ht-docker-node:npmci
stage: pages
script: script:
- npmci node install lts - npmci command yarn global add npmpage
- npmci command npm install -g @gitzone/tsdoc - npmci command npmpage
- npmci npm prepare
- npmci npm install
- npmci command tsdoc
tags: tags:
- lossless
- docker - docker
- notpriv
only: only:
- tags - tags
artifacts: artifacts:
expire_in: 1 week expire_in: 1 week
paths: paths:
- public - public
allow_failure: true

29
.vscode/launch.json vendored
View File

@ -1,29 +0,0 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "current file",
"type": "node",
"request": "launch",
"args": [
"${relativeFile}"
],
"runtimeArgs": ["-r", "@gitzone/tsrun"],
"cwd": "${workspaceRoot}",
"protocol": "inspector",
"internalConsoleOptions": "openOnSessionStart"
},
{
"name": "test.ts",
"type": "node",
"request": "launch",
"args": [
"test/test.ts"
],
"runtimeArgs": ["-r", "@gitzone/tsrun"],
"cwd": "${workspaceRoot}",
"protocol": "inspector",
"internalConsoleOptions": "openOnSessionStart"
}
]
}

26
.vscode/settings.json vendored
View File

@ -1,26 +0,0 @@
{
"json.schemas": [
{
"fileMatch": ["/npmextra.json"],
"schema": {
"type": "object",
"properties": {
"npmci": {
"type": "object",
"description": "settings for npmci"
},
"gitzone": {
"type": "object",
"description": "settings for gitzone",
"properties": {
"projectType": {
"type": "string",
"enum": ["website", "element", "service", "npm", "wcc"]
}
}
}
}
}
}
]
}

View File

@ -13,7 +13,6 @@
}, },
"npmci": { "npmci": {
"npmGlobalTools": [], "npmGlobalTools": [],
"npmRegistryUrl": "registry.npmjs.org",
"npmAccessLevel": "public" "npmAccessLevel": "public"
} }
} }

20125
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
{ {
"name": "@mojoio/gitlab", "name": "@mojoio/gitlab",
"version": "1.0.10", "version": "1.0.4",
"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,33 +11,15 @@
"build": "(tsbuild --web)" "build": "(tsbuild --web)"
}, },
"devDependencies": { "devDependencies": {
"@gitzone/tsbuild": "^2.1.27", "@gitzone/tsbuild": "^2.1.25",
"@gitzone/tsrun": "^1.2.17", "@gitzone/tsrun": "^1.2.12",
"@gitzone/tstest": "^1.0.57", "@gitzone/tstest": "^1.0.54",
"@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"
}, },
"dependencies": { "dependencies": {
"@pushrocks/smartfile": "^8.0.10", "@pushrocks/smartrequest": "^1.1.51",
"@pushrocks/smartrequest": "^1.1.52", "@pushrocks/smarturl": "^2.0.1"
"@pushrocks/smarturl": "^2.0.1", }
"@tsclass/tsclass": "^3.0.34"
},
"private": false,
"browserslist": [
"last 1 chrome versions"
],
"files": [
"ts/**/*",
"ts_web/**/*",
"dist/**/*",
"dist_*/**/*",
"dist_ts/**/*",
"dist_ts_web/**/*",
"assets/**/*",
"cli.js",
"npmextra.json",
"readme.md"
]
} }

View File

@ -1,46 +1,29 @@
# @mojoio/gitlab # glab
a gitlab api abstraction package api abstraction package for gitlab
## Availabililty and Links ## Availabililty
* [npmjs.org (npm package)](https://www.npmjs.com/package/@mojoio/gitlab) [![npm](https://mojoio.gitlab.io/assets/repo-button-npm.svg)](https://www.npmjs.com/package/glab)
* [gitlab.com (source)](https://gitlab.com/mojoio/gitlab) [![git](https://mojoio.gitlab.io/assets/repo-button-git.svg)](https://GitLab.com/mojoio/glab)
* [github.com (source mirror)](https://github.com/mojoio/gitlab) [![git](https://mojoio.gitlab.io/assets/repo-button-mirror.svg)](https://github.com/mojoio/glab)
* [docs (typedoc)](https://mojoio.gitlab.io/gitlab/) [![docs](https://mojoio.gitlab.io/assets/repo-button-docs.svg)](https://mojoio.gitlab.io/glab/)
## Status for master ## Status for master
[![build status](https://GitLab.com/mojoio/glab/badges/master/build.svg)](https://GitLab.com/mojoio/glab/commits/master)
Status Category | Status Badge [![coverage report](https://GitLab.com/mojoio/glab/badges/master/coverage.svg)](https://GitLab.com/mojoio/glab/commits/master)
-- | -- [![npm downloads per month](https://img.shields.io/npm/dm/glab.svg)](https://www.npmjs.com/package/glab)
GitLab Pipelines | [![pipeline status](https://gitlab.com/mojoio/gitlab/badges/master/pipeline.svg)](https://lossless.cloud) [![Dependency Status](https://david-dm.org/mojoio/glab.svg)](https://david-dm.org/mojoio/glab)
GitLab Pipline Test Coverage | [![coverage report](https://gitlab.com/mojoio/gitlab/badges/master/coverage.svg)](https://lossless.cloud) [![bitHound Dependencies](https://www.bithound.io/github/mojoio/glab/badges/dependencies.svg)](https://www.bithound.io/github/mojoio/glab/master/dependencies/npm)
npm | [![npm downloads per month](https://badgen.net/npm/dy/@mojoio/gitlab)](https://lossless.cloud) [![bitHound Code](https://www.bithound.io/github/mojoio/glab/badges/code.svg)](https://www.bithound.io/github/mojoio/glab)
Snyk | [![Known Vulnerabilities](https://badgen.net/snyk/mojoio/gitlab)](https://lossless.cloud) [![TypeScript](https://img.shields.io/badge/TypeScript-2.x-blue.svg)](https://nodejs.org/dist/latest-v6.x/docs/api/)
TypeScript Support | [![TypeScript](https://badgen.net/badge/TypeScript/>=%203.x/blue?icon=typescript)](https://lossless.cloud) [![node](https://img.shields.io/badge/node->=%206.x.x-blue.svg)](https://nodejs.org/dist/latest-v6.x/docs/api/)
node Support | [![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/) [![JavaScript Style Guide](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/)
Code Style | [![Code Style](https://badgen.net/badge/style/prettier/purple)](https://lossless.cloud)
PackagePhobia (total standalone install weight) | [![PackagePhobia](https://badgen.net/packagephobia/install/@mojoio/gitlab)](https://lossless.cloud)
PackagePhobia (package size on registry) | [![PackagePhobia](https://badgen.net/packagephobia/publish/@mojoio/gitlab)](https://lossless.cloud)
BundlePhobia (total size when bundled) | [![BundlePhobia](https://badgen.net/bundlephobia/minzip/@mojoio/gitlab)](https://lossless.cloud)
Platform support | [![Supports Windows 10](https://badgen.net/badge/supports%20Windows%2010/yes/green?icon=windows)](https://lossless.cloud) [![Supports Mac OS X](https://badgen.net/badge/supports%20Mac%20OS%20X/yes/green?icon=apple)](https://lossless.cloud)
## Usage ## Usage
Use TypeScript for best in class instellisense. Use TypeScript for best in class instellisense.
For further information read the linked docs at the top of this README. For further information read the linked docs at the top of this README.
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh) > MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
> | By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html) | By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
[![repo-footer](https://mojoio.gitlab.io/assets/repo-footer.svg)](https://mojo.io) [![repo-footer](https://mojoio.gitlab.io/assets/repo-footer.svg)](https://mojo.io)
## 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). :)
For further information read the linked docs at the top of this readme.
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
[![repo-footer](https://lossless.gitlab.io/publicrelations/repofooter.svg)](https://maintainedby.lossless.com)

View File

@ -1,43 +1,23 @@
import { expect, tap } from '@pushrocks/tapbundle'; import { expect, tap } from '@pushrocks/tapbundle'
import * as gitlab from '../ts/index'; import * as gitlab from '../ts/index';
let testGitlabAccount: gitlab.GitlabAccount; let testGitlabAccount: gitlab.GitlabAccount;
const test1 = tap.test('should create an anonymous Gitlab Account', async () => { 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);
}); });
const test2 = tap.test('should get the pushrocks group', async () => { 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);
}); });
const test3 = tap.test('should get the pushrocks group', async () => { 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();
}); });
const test4 = tap.test('should get the readme of a project', async () => {
const pushrocksGroup = await testGitlabAccount.getGroupByName('pushrocks');
expect(pushrocksGroup).to.be.instanceOf(gitlab.GitlabGroup);
const projects = await pushrocksGroup.getProjects();
const selectedProject = projects.find((project) => {
return project.data?.name === 'smartfile';
});
expect(selectedProject.data.name).to.equal('smartfile');
const readme = await selectedProject.getReadmeAsMarkdown('master');
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();

View File

@ -11,29 +11,23 @@ export class GitlabAccount {
return GitlabGroup.getByName(nameArg, this); return GitlabGroup.getByName(nameArg, this);
} }
/** /**
* handles the basic request/response patterns with the gitlab.com API * handles the basic request/response patterns with the gitlab.com API
*/ */
public async request( public async request (methodArg: 'GET' | 'POST', routeArg: string, searchParamsArg: {[key: string]: string}) {
methodArg: 'GET' | 'POST', if(!routeArg.startsWith('/')) {
routeArg: string,
searchParamsArg: { [key: string]: string }
) {
if (!routeArg.startsWith('/')) {
throw new Error(`"${routeArg}" -> routeArg must start with a slash`); throw new Error(`"${routeArg}" -> routeArg must start with a slash`);
} }
const smarturlInstance = plugins.smarturl.Smarturl.createFromUrl( const smarturlInstance = plugins.smarturl.Smarturl.createFromUrl(`https://gitlab.com/api/v4${routeArg}`, {
`https://gitlab.com/api/v4${routeArg}`, searchParams: searchParamsArg
{ });
searchParams: searchParamsArg,
}
);
const response = await plugins.smartrequest.request(smarturlInstance.toString(), { const response = await plugins.smartrequest.request(smarturlInstance.toString(), {
method: methodArg, method: methodArg
}); });
// lets deal with pagination headers // lets deal with pagination headers
const findLinkName = (markup: string) => { const fintLinkName = (markup) => {
const pattern = /<([^\s>]+)(\s|>)+/; const pattern = /<([^\s>]+)(\s|>)+/;
return markup.match(pattern)[1]; return markup.match(pattern)[1];
}; };
@ -43,21 +37,6 @@ export class GitlabAccount {
original: string; original: string;
link: string; link: string;
}[] = []; }[] = [];
for (const link of links) {
linkObjects.push({
original: link,
link: findLinkName(link),
});
}
const next = linkObjects.find((linkObject) => linkObject.original.includes('rel="next"'));
if (next && response.body instanceof Array) {
const nextResponse = await this.request(
methodArg,
next.link.replace('https://gitlab.com/api/v4', ''),
{}
);
response.body = response.body.concat(nextResponse);
}
} }
return response.body; return response.body;
} }

View File

@ -1,173 +1,27 @@
import { GitlabGroup } from './gitlab.classes.group'; import { GitlabGroup } from './gitlab.classes.group';
import * as plugins from './gitlab.plugins'; import * as plugins from './gitlab.plugins';
export interface IGitlabData {
id: number;
description: string;
name: string;
name_with_namespace: string;
path: string;
path_with_namespace: string;
created_at: string;
default_branch: string;
tag_list: string[];
ssh_url_to_repo: string;
http_url_to_repo: string;
web_url: string;
readme_url: string;
avatar_url: null;
forks_count: number;
star_count: number;
last_activity_at: string;
namespace: {
id: number;
name: string;
path: string;
kind: string;
full_path: string;
parent_id: null;
avatar_url: string;
web_url: string;
};
container_registry_image_prefix: string;
_links: {
self: string;
issues: string;
merge_requests: string;
repo_branches: string;
labels: string;
events: string;
members: string;
};
packages_enabled: null;
empty_repo: boolean;
archived: boolean;
visibility: 'public' | 'private';
resolve_outdated_diff_discussions: null;
container_registry_enabled: boolean;
issues_enabled: boolean;
merge_requests_enabled: boolean;
wiki_enabled: boolean;
jobs_enabled: boolean;
snippets_enabled: boolean;
service_desk_enabled: null;
service_desk_address: null;
can_create_merge_request_in: boolean;
issues_access_level: 'enabled' | 'disabled';
repository_access_level: 'enabled' | 'disabled';
merge_requests_access_level: 'enabled' | 'disabled';
forking_access_level: 'enabled' | 'disabled';
wiki_access_level: 'enabled' | 'disabled';
builds_access_level: 'enabled' | 'disabled';
snippets_access_level: 'enabled' | 'disabled';
pages_access_level: 'enabled' | 'disabled';
operations_access_level: 'enabled' | 'disabled';
analytics_access_level: 'enabled' | 'disabled';
emails_disabled: null;
shared_runners_enabled: boolean;
lfs_enabled: boolean;
creator_id: number;
import_status: 'none';
open_issues_count: number;
ci_default_git_depth: null;
ci_forward_deployment_enabled: null;
public_jobs: boolean;
build_timeout: number;
auto_cancel_pending_pipelines: 'enabled' | 'disabled';
build_coverage_regex: '';
ci_config_path: '';
shared_with_groups: [];
only_allow_merge_if_pipeline_succeeds: boolean;
allow_merge_on_skipped_pipeline: null;
restrict_user_defined_variables: boolean;
request_access_enabled: boolean;
only_allow_merge_if_all_discussions_are_resolved: boolean;
remove_source_branch_after_merge: null;
printing_merge_request_link_enabled: boolean;
merge_method: 'merge';
suggestion_commit_message: null;
auto_devops_enabled: boolean;
auto_devops_deploy_strategy: 'continuous';
autoclose_referenced_issues: boolean;
approvals_before_merge: number;
mirror: boolean;
external_authorization_classification_label: '';
marked_for_deletion_at: null;
marked_for_deletion_on: null;
requirements_enabled: boolean;
security_and_compliance_enabled: null;
compliance_frameworks: [];
issues_template: '';
merge_requests_template: '';
}
export class GitlabProject { export class GitlabProject {
// STATIC // STATIC
public static async getProjectsForGroup(gitlabGroupArg: GitlabGroup): Promise<GitlabProject[]> { public static async getProjectsForGroup(gitlabGroupArg: GitlabGroup) {
const response = await gitlabGroupArg.gitlabAccountRef.request( const response = await gitlabGroupArg.gitlabAccountRef.request('GET', `/groups/${gitlabGroupArg.data.id}/projects`, {
'GET', per_page: '100'
`/groups/${gitlabGroupArg.data.id}/projects`, });
{ console.log(response);
per_page: '100',
}
);
const allProjects: GitlabProject[] = [];
for (const projectData of response) { for (const projectData of response) {
allProjects.push(new GitlabProject(projectData, gitlabGroupArg)); console.log(projectData);
} }
return allProjects; console.log(response.length);
} }
// INSTANCE // INSTANCE
gitlabGroupRef: GitlabGroup; gitlabGroupRef: GitlabGroup;
data: IGitlabData; data: any;
constructor(dataArg: IGitlabData, gitlabGroupRefArg: GitlabGroup) { constructor(dataArg: any, gitlabGroupRefArg: GitlabGroup) {
this.data = dataArg; this.data = dataArg;
this.gitlabGroupRef = gitlabGroupRefArg; this.gitlabGroupRef = gitlabGroupRefArg;
} }
public async getFileFromProject( public async getReadmeAsMarkdown() {};
filePathArg: string,
refArg: string
): Promise<plugins.smartfile.Smartfile> {
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> {
const readmeFile = await this.getFileFromProject('readme.md', refArg);
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() {
}
} }

View File

@ -1,13 +1,8 @@
// @tsclass scope
import * as tsclass from '@tsclass/tsclass';
export {
tsclass
}
// pushrocks scope // pushrocks scope
import * as smartfile from '@pushrocks/smartfile';
import * as smartrequest from '@pushrocks/smartrequest'; import * as smartrequest from '@pushrocks/smartrequest';
import * as smarturl from '@pushrocks/smarturl'; import * as smarturl from '@pushrocks/smarturl';
export { smartfile, smartrequest, smarturl }; export {
smartrequest,
smarturl
};

View File

@ -1,3 +1,2 @@
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';