@hestia-earth/pipeline-utils 0.10.2 → 0.10.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +9 -0
- package/dist/gitlab.d.ts +9 -0
- package/dist/gitlab.js +29 -0
- package/dist/gitlab.js.map +1 -0
- package/package.json +4 -2
- package/src/gitlab.ts +34 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
### [0.10.4](https://gitlab.com/hestia-earth/hestia-pipeline-utils/compare/v0.10.3...v0.10.4) (2023-06-15)
|
|
6
|
+
|
|
7
|
+
### [0.10.3](https://gitlab.com/hestia-earth/hestia-pipeline-utils/compare/v0.10.2...v0.10.3) (2023-06-15)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
### Features
|
|
11
|
+
|
|
12
|
+
* **gitlab:** add `listFiles` and `readFile` functions ([76b4daa](https://gitlab.com/hestia-earth/hestia-pipeline-utils/commit/76b4daa2eeb23d15b5a09637756fc0c7c3200aed))
|
|
13
|
+
|
|
5
14
|
### [0.10.2](https://gitlab.com/hestia-earth/hestia-pipeline-utils/compare/v0.10.1...v0.10.2) (2023-06-13)
|
|
6
15
|
|
|
7
16
|
|
package/dist/gitlab.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Readable } from 'stream';
|
|
3
|
+
export interface IGitlabFile {
|
|
4
|
+
id?: string;
|
|
5
|
+
name: string;
|
|
6
|
+
path: string;
|
|
7
|
+
}
|
|
8
|
+
export declare const listFiles: (path?: string, page?: number, limit?: number) => Promise<IGitlabFile[]>;
|
|
9
|
+
export declare const readFile: ({ id }: Partial<IGitlabFile>) => Promise<Readable>;
|
package/dist/gitlab.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.readFile = exports.listFiles = void 0;
|
|
4
|
+
const axios_1 = require("axios");
|
|
5
|
+
const token = process.env.GITLAB_TOKEN;
|
|
6
|
+
const projectId = process.env.GITLAB_PROJECT_ID;
|
|
7
|
+
const branch = process.env.GITLAB_BRANCH;
|
|
8
|
+
const gitlabUrl = `https://gitlab.com/api/v4/projects/${projectId}`;
|
|
9
|
+
const headers = { 'PRIVATE-TOKEN': token };
|
|
10
|
+
const listFiles = async (path, page = 1, limit = 100) => {
|
|
11
|
+
const { data } = await axios_1.default.get(`${gitlabUrl}/repository/tree`, {
|
|
12
|
+
headers: { 'PRIVATE-TOKEN': token },
|
|
13
|
+
params: { page, per_page: limit, ref: branch, path }
|
|
14
|
+
});
|
|
15
|
+
return [
|
|
16
|
+
...data,
|
|
17
|
+
...(data.length === limit ? await (0, exports.listFiles)(path, page + 1) : [])
|
|
18
|
+
];
|
|
19
|
+
};
|
|
20
|
+
exports.listFiles = listFiles;
|
|
21
|
+
const readFile = async ({ id }) => {
|
|
22
|
+
const { data } = await axios_1.default.get(`${gitlabUrl}/repository/blobs/${id}/raw`, {
|
|
23
|
+
headers,
|
|
24
|
+
responseType: 'stream'
|
|
25
|
+
});
|
|
26
|
+
return data;
|
|
27
|
+
};
|
|
28
|
+
exports.readFile = readFile;
|
|
29
|
+
//# sourceMappingURL=gitlab.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gitlab.js","sourceRoot":"","sources":["../src/gitlab.ts"],"names":[],"mappings":";;;AACA,iCAA0B;AAQ1B,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC;AACvC,MAAM,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC;AAChD,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC;AAEzC,MAAM,SAAS,GAAG,sCAAsC,SAAS,EAAE,CAAC;AACpE,MAAM,OAAO,GAAG,EAAE,eAAe,EAAE,KAAK,EAAE,CAAC;AAEpC,MAAM,SAAS,GAAG,KAAK,EAAE,IAAa,EAAE,IAAI,GAAG,CAAC,EAAE,KAAK,GAAG,GAAG,EAA0B,EAAE;IAC9F,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,eAAK,CAAC,GAAG,CAAgB,GAAG,SAAS,kBAAkB,EAAE;QAC9E,OAAO,EAAE,EAAE,eAAe,EAAE,KAAK,EAAE;QACnC,MAAM,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE;KACrD,CAAC,CAAC;IACH,OAAO;QACL,GAAG,IAAI;QACP,GAAG,CAAC,IAAI,CAAC,MAAM,KAAK,KAAK,CAAC,CAAC,CAAC,MAAM,IAAA,iBAAS,EAAC,IAAI,EAAE,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;KAClE,CAAC;AACJ,CAAC,CAAC;AATW,QAAA,SAAS,aASpB;AAEK,MAAM,QAAQ,GAAG,KAAK,EAAE,EAAE,EAAE,EAAwB,EAAE,EAAE;IAC7D,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,eAAK,CAAC,GAAG,CAAW,GAAG,SAAS,qBAAqB,EAAE,MAAM,EAAE;QACpF,OAAO;QACP,YAAY,EAAE,QAAQ;KACvB,CAAC,CAAC;IACH,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AANW,QAAA,QAAQ,YAMnB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hestia-earth/pipeline-utils",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.4",
|
|
4
4
|
"description": "Utilities for running pipelines",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
@@ -41,7 +41,8 @@
|
|
|
41
41
|
"@hestia-earth/api": ">=0.19.0",
|
|
42
42
|
"@hestia-earth/json-schema": ">=20.0.0",
|
|
43
43
|
"@hestia-earth/schema": ">=20.0.0",
|
|
44
|
-
"@hestia-earth/utils": ">=0.11.2"
|
|
44
|
+
"@hestia-earth/utils": ">=0.11.2",
|
|
45
|
+
"axios": "^1.0.0"
|
|
45
46
|
},
|
|
46
47
|
"devDependencies": {
|
|
47
48
|
"@commitlint/cli": "^17.4.2",
|
|
@@ -63,6 +64,7 @@
|
|
|
63
64
|
"@types/sinon": "^9.0.11",
|
|
64
65
|
"@typescript-eslint/eslint-plugin": "^5.27.1",
|
|
65
66
|
"@typescript-eslint/parser": "^5.27.1",
|
|
67
|
+
"axios": "^1.4.0",
|
|
66
68
|
"chai": "^4.3.7",
|
|
67
69
|
"eslint": "^7.32.0",
|
|
68
70
|
"eslint-plugin-jsdoc": "^30.7.13",
|
package/src/gitlab.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Readable } from 'stream';
|
|
2
|
+
import axios from 'axios';
|
|
3
|
+
|
|
4
|
+
export interface IGitlabFile {
|
|
5
|
+
id?: string;
|
|
6
|
+
name: string;
|
|
7
|
+
path: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const token = process.env.GITLAB_TOKEN;
|
|
11
|
+
const projectId = process.env.GITLAB_PROJECT_ID;
|
|
12
|
+
const branch = process.env.GITLAB_BRANCH;
|
|
13
|
+
|
|
14
|
+
const gitlabUrl = `https://gitlab.com/api/v4/projects/${projectId}`;
|
|
15
|
+
const headers = { 'PRIVATE-TOKEN': token };
|
|
16
|
+
|
|
17
|
+
export const listFiles = async (path?: string, page = 1, limit = 100): Promise<IGitlabFile[]> => {
|
|
18
|
+
const { data } = await axios.get<IGitlabFile[]>(`${gitlabUrl}/repository/tree`, {
|
|
19
|
+
headers: { 'PRIVATE-TOKEN': token },
|
|
20
|
+
params: { page, per_page: limit, ref: branch, path }
|
|
21
|
+
});
|
|
22
|
+
return [
|
|
23
|
+
...data,
|
|
24
|
+
...(data.length === limit ? await listFiles(path, page + 1) : [])
|
|
25
|
+
];
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export const readFile = async ({ id }: Partial<IGitlabFile>) => {
|
|
29
|
+
const { data } = await axios.get<Readable>(`${gitlabUrl}/repository/blobs/${id}/raw`, {
|
|
30
|
+
headers,
|
|
31
|
+
responseType: 'stream'
|
|
32
|
+
});
|
|
33
|
+
return data;
|
|
34
|
+
};
|