gitlab-projects-library
v2.8.3
Published
A library to get projects and install them from Gitlab using simple-git
Downloads
161
Readme
Table of Contents
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.