@hestia-earth/pipeline-utils 0.10.4 → 0.11.0

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 CHANGED
@@ -2,6 +2,17 @@
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.11.0](https://gitlab.com/hestia-earth/hestia-pipeline-utils/compare/v0.10.4...v0.11.0) (2023-06-16)
6
+
7
+
8
+ ### ⚠ BREAKING CHANGES
9
+
10
+ * **gitlab:** `readFile` in gitlab has been renamed `readFileRaw`
11
+
12
+ ### Features
13
+
14
+ * **gitlab:** add function to retrun file content ([cec9f1e](https://gitlab.com/hestia-earth/hestia-pipeline-utils/commit/cec9f1e818994925837ade5e3cfc4498e724212f))
15
+
5
16
  ### [0.10.4](https://gitlab.com/hestia-earth/hestia-pipeline-utils/compare/v0.10.3...v0.10.4) (2023-06-15)
6
17
 
7
18
  ### [0.10.3](https://gitlab.com/hestia-earth/hestia-pipeline-utils/compare/v0.10.2...v0.10.3) (2023-06-15)
package/dist/gitlab.d.ts CHANGED
@@ -1,9 +1,14 @@
1
1
  /// <reference types="node" />
2
2
  import { Readable } from 'stream';
3
- export interface IGitlabFile {
3
+ export interface IGitlabTreeFile {
4
4
  id?: string;
5
5
  name: string;
6
6
  path: string;
7
7
  }
8
- export declare const listFiles: (path?: string, page?: number, limit?: number) => Promise<IGitlabFile[]>;
9
- export declare const readFile: ({ id }: Partial<IGitlabFile>) => Promise<Readable>;
8
+ export interface IGitlabFile {
9
+ size: number;
10
+ content: string;
11
+ }
12
+ export declare const listFiles: (path: string, page?: number, limit?: number) => Promise<IGitlabTreeFile[]>;
13
+ export declare const readFile: ({ path }: Partial<IGitlabTreeFile>) => Promise<IGitlabFile>;
14
+ export declare const readFileRaw: ({ id }: Partial<IGitlabTreeFile>) => Promise<Readable>;
package/dist/gitlab.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.readFile = exports.listFiles = void 0;
3
+ exports.readFileRaw = exports.readFile = exports.listFiles = void 0;
4
4
  const axios_1 = require("axios");
5
5
  const token = process.env.GITLAB_TOKEN;
6
6
  const projectId = process.env.GITLAB_PROJECT_ID;
@@ -9,7 +9,7 @@ const gitlabUrl = `https://gitlab.com/api/v4/projects/${projectId}`;
9
9
  const headers = { 'PRIVATE-TOKEN': token };
10
10
  const listFiles = async (path, page = 1, limit = 100) => {
11
11
  const { data } = await axios_1.default.get(`${gitlabUrl}/repository/tree`, {
12
- headers: { 'PRIVATE-TOKEN': token },
12
+ headers,
13
13
  params: { page, per_page: limit, ref: branch, path }
14
14
  });
15
15
  return [
@@ -18,12 +18,20 @@ const listFiles = async (path, page = 1, limit = 100) => {
18
18
  ];
19
19
  };
20
20
  exports.listFiles = listFiles;
21
- const readFile = async ({ id }) => {
21
+ const readFile = async ({ path }) => {
22
+ const { data } = await axios_1.default.get(`${gitlabUrl}/repository/files/${encodeURIComponent(path)}`, {
23
+ headers,
24
+ params: { ref: branch }
25
+ });
26
+ return data;
27
+ };
28
+ exports.readFile = readFile;
29
+ const readFileRaw = async ({ id }) => {
22
30
  const { data } = await axios_1.default.get(`${gitlabUrl}/repository/blobs/${id}/raw`, {
23
31
  headers,
24
32
  responseType: 'stream'
25
33
  });
26
34
  return data;
27
35
  };
28
- exports.readFile = readFile;
36
+ exports.readFileRaw = readFileRaw;
29
37
  //# sourceMappingURL=gitlab.js.map
@@ -1 +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,CA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AAM,EAAE;QACpF,OAAO;QACP,YAAY,EAAE,QAAQ;KACvB,CAAC,CAAC;IACH,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AANW,QAAA,WAAW,eAMtB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hestia-earth/pipeline-utils",
3
- "version": "0.10.4",
3
+ "version": "0.11.0",
4
4
  "description": "Utilities for running pipelines",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
package/src/gitlab.ts CHANGED
@@ -1,12 +1,17 @@
1
1
  import { Readable } from 'stream';
2
2
  import axios from 'axios';
3
3
 
4
- export interface IGitlabFile {
4
+ export interface IGitlabTreeFile {
5
5
  id?: string;
6
6
  name: string;
7
7
  path: string;
8
8
  }
9
9
 
10
+ export interface IGitlabFile {
11
+ size: number;
12
+ content: string;
13
+ }
14
+
10
15
  const token = process.env.GITLAB_TOKEN;
11
16
  const projectId = process.env.GITLAB_PROJECT_ID;
12
17
  const branch = process.env.GITLAB_BRANCH;
@@ -14,9 +19,9 @@ const branch = process.env.GITLAB_BRANCH;
14
19
  const gitlabUrl = `https://gitlab.com/api/v4/projects/${projectId}`;
15
20
  const headers = { 'PRIVATE-TOKEN': token };
16
21
 
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 },
22
+ export const listFiles = async (path: string, page = 1, limit = 100): Promise<IGitlabTreeFile[]> => {
23
+ const { data } = await axios.get<IGitlabTreeFile[]>(`${gitlabUrl}/repository/tree`, {
24
+ headers,
20
25
  params: { page, per_page: limit, ref: branch, path }
21
26
  });
22
27
  return [
@@ -25,7 +30,15 @@ export const listFiles = async (path?: string, page = 1, limit = 100): Promise<I
25
30
  ];
26
31
  };
27
32
 
28
- export const readFile = async ({ id }: Partial<IGitlabFile>) => {
33
+ export const readFile = async ({ path }: Partial<IGitlabTreeFile>) => {
34
+ const { data } = await axios.get<IGitlabFile>(`${gitlabUrl}/repository/files/${encodeURIComponent(path)}`, {
35
+ headers,
36
+ params: { ref: branch }
37
+ });
38
+ return data;
39
+ };
40
+
41
+ export const readFileRaw = async ({ id }: Partial<IGitlabTreeFile>) => {
29
42
  const { data } = await axios.get<Readable>(`${gitlabUrl}/repository/blobs/${id}/raw`, {
30
43
  headers,
31
44
  responseType: 'stream'