gitlab-projects-library
TypeScript icon, indicating that this package has built-in type declarations

2.8.3 • Public • Published

Table of Contents

  1. Description
  2. Pre-requisites
  3. Usage
  4. Installation
  5. Contributing
  6. Tests
  7. License

Description

This project is a library that is mainly used in the context of the application SI Manager.

Its goal is to be able to list and clone information systems that are stored in a Gitlab repository in a specific group.

Pre-requisites

The library uses two environment variables to authenticate to the Gitlab API.

The following environment variables need to be set:

  • GITLAB_TOKEN_NAME: The name of the token to use to authenticate to the Gitlab API.
  • GITLAB_TOKEN_VALUE: The value of the token to use to authenticate to the Gitlab API.

You can set the environment variables in the environment when you invoke the GitlabProjectsManager.

Usage

The module can be used like the following :

import { GitlabProjectsManager } from "gitlab-projects-library";

const credentials = {
  tokenName: "GITLAB_TOKEN_NAME",
  tokenValue: "GITLAB_TOKEN_VALUE",
};

const manager = new GitlabProjectsManager({
  outputDir: "projects",
  tokenName: credentials.tokenName,
  tokenValue: credentials.tokenValue,
});

And then use one of the methods of the class:

// List projects
const listResult = await manager.listProjects({
  "https://forgemia.inra.fr",
  18500,
});

// Clone project
const result = await manager.cloneProject({
  httpUrl: "https://forgemia.inra.fr/anaee-dev/si_projects/si_template.git",
});

Installation

As a library

The library can be imported in a Node.js project.

"dependencies": {
    "si-projects-library": "latest"
}

As a script

The library can also be used as a script. A pre-existing command is available to run the script in the package.json file. This pre-existing command can be executed directly with the following command:

yarn run start

Contributing

The project has been developped with

  • Node lts/iron (v20.9.0)
  • Yarn 1.22.19

To use nvm to manage your node versions, you can follow the instructions here.

You can then install the version of node you need with the following command:

nvm install lts/iron

And then install yarn with the following command:

npm install -g yarn

To install the dependencies, you then need to run the following command:

yarn install

or

npm install

Tests

Tests have been written with Jest and can be found in the tests folder.

They need a .env file to be able to run them, as they will try to call the Gitlab API.

The .env file should contain the following:

GITLAB_TOKEN_NAME=GITLAB_TOKEN_NAME
GITLAB_TOKEN_VALUE=GITLAB_TOKEN_VALUE

To run the tests, you can use the following command:

yarn run test

License

This project is licensed under the MIT License - see the LICENSE file for details.

Readme

Keywords

none

Package Sidebar

Install

npm i gitlab-projects-library

Weekly Downloads

0

Version

2.8.3

License

MIT

Unpacked Size

31.8 kB

Total Files

31

Last publish

Collaborators

  • bchoquet