npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

gitlab-restapi

v1.1.17

Published

Integration with GitLab REST API

Downloads

396

Readme

Integration with GitLab REST API

os, nodes npm version Downloads/month Vulnerabilities

The module allows you to perform the list of methods described in the GitLab service documentation in the section Jobs , Pipelines ( for now)

And you can Add your own method that is not yet implemented by this api

  • List project jobs
  • List pipeline jobs
  • List pipeline trigger jobs
  • Get job token’s job
  • Get GitLab agent by CI_JOB_TOKEN
  • Get a single job
  • Get a log file
  • Cancel a job
  • Retry a job
  • Erase a job
  • Run a job
  • List project pipelines
  • Get a single pipeline
  • Get variables of a pipeline
  • Get a pipeline’s test report
  • Get a pipeline’s test report summary
  • Get the latest pipeline
  • Create a new pipeline
  • Retry jobs in a pipeline
  • Cancel a pipeline’s jobs
  • Delete a pipeline

read more

And yes, let's start!

☕️ buy me a coffee

Installation

First install Node.js

npm i gitlab-restapi

An example of receiving a list of tasks divided into pages with the specified status

const GitLab = require("gitlab-restapi");
const gitLab = new GitLab.API(new GitLab.Options({
    privateToken: process.env.GIT_TOKEN,
    projectId: process.env.GIT_PID,
}));

const jobs = await gitLab.Jobs.jobs(
    new GitLab.PaginateParams({
        page: 1, per_page: 100, scope: ['success', 'failed']
    }));
// find first(last executed) Job by name
const job = jobs.find({name: 'testofclasses'});
console.log(job.status)

scope

  • string or array of strings - Scope of jobs to show. Either one of or an array of the following: created, pending, running, failed, success, canceled, skipped, waiting_for_resource, or manual. All jobs are returned if scope is not provided.

GitLab.Options can specify your method for fetching data. For nodes 18+ - this is the own node fetch, for younger versions (unless otherwise specified) - the internal mechanism

new GitLab.Options({
    privateToken: process.env.GIT_TOKEN,
    projectId: process.env.GIT_PID,
    fetchMethod: fetch // axios, fetch, node-fetch, GitLab.Request (tested)
})

List of Jobs methods:

const GitLab = require("gitlab-restapi");
const gitLab = new GitLab.API(new GitLab.Options({
    privateToken: process.env.GIT_TOKEN,
    projectId: process.env.GIT_PID,
    fetchMethod: fetch // axios, fetch, node-fetch, GitLab.Request (tested)
}));
console.log(gitLab.Jobs.methods)

// list of registered APIs
console.log(gitLab.getOwnPropertyNames())

Get a single job of a project

const jobs = await gitLab.Jobs.jobs(
    new GitLab.PaginateParams({page: 1, per_page: 1, scope: ['success']}));
// const jobs = await gitLab.Jobs.jobs(new GitLab.PaginateParams({})); // page: 1, per_page: 20, all scopes
// const jobs = await gitLab.Jobs.jobs(); // page: 1, per_page: 20, all scopes
console.log('jobs:', jobs.list)

const _job = jobs.find({status: 'success'});
console.log('found:', _job)

const job = await gitLab.Jobs.job(_job.id);
console.log('Get a single job of a project by id:', job)

Erase a single job of a project (remove job artifacts and a job log)

const jobs = await gitLab.Jobs.jobs(new GitLab.PaginateParams({
    page: 1,
    per_page: 100,
    scope: ['failed', 'canceled']
}));
const erasedJobs = new GitLab.Jobs([])
for (let job of jobs.list) {
    if (job.artifacts && job.artifacts.length) {
        const obj = await gitLab.Jobs.erase(job.id);
        if (obj) erasedJobs.push(obj)
    }
}
console.log(erasedJobs.list)

Pipelines

const pipelinelatest = await gitLab.Pipelines.latest();
console.log(pipelinelatest)

const pipelines = await gitLab.Pipelines.pipelines(new GitLab.PaginateParams({
    page: 1, per_page: 20,  status: 'success', source: 'push',}));
console.log(pipelines.list)

Add your own method that is not yet implemented by this api

gitLab.add('MyGroups').addMethods({
    groups: new GitLab.Method({method: 'get', class: GitLab.Responses, 
        url: () => `groups`})
})
console.log(gitLab.MyGroups.methods)

const groups = await gitLab.MyGroups.groups(
    new GitLab.PaginateParams({page: 2, per_page: 20}));
console.log(groups.list)

Releases

gitLab.add('MyReleases').addMethods({
    releases: new GitLab.Method({method: 'get', class: GitLab.Responses, 
        url: () => `projects/${gitLab.projectId}/releases`})
})
console.log(gitLab.MyReleases.methods)

const releases = await gitLab.MyReleases.releases(new GitLab.PaginateParams({page: 2, per_page: 20}));
console.log(releases.list)

Thanks for your attention - the continuation of the api will come soon