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-bta

v0.5.1

Published

Inspired from the GitLab Triage Bot, this bot only use the GitLab API (BTA for Bot Triage Api). So there is some functionnality more difficult to do but other more simple.

Downloads

33

Readme

pipeline status coverage report npm version

Inspired from the GitLab Triage Bot, this bot only use the GitLab API. So there is some functionnality more difficult to do but other more simple.

If it is in the API you can use it.

Installation

To intall it, just run

npm install -g gitlab-bta

Use

# gitlab-bta --help
gitlab-bta [command]

Commands:
  gitlab-bta ./cli.js  Make some automatic triage on issues and MR

Options:
  --version            Show version number                             [boolean]
  --dry-run, -n        Don't actually update anything, just print
                                                      [boolean] [default: false]
  --host-url, -H       A valid host url[string] [default: "https://gitlab.com/"]
  --token, -t          A valid API token                     [string] [required]
  --source-id, -s      GitLab project ID                     [string] [required]
  --timeout, -T        API call timeout (ms)           [number] [default: 10000]
  --policies-file, -f  A valid policies JS file
                                            [string] [default: "../policies.js"]
  --help, -h           Show help                                       [boolean]

In your gitlab-ci.yml file you can add jobs like this:

stages:
  - triage

.triage:
  image: node:8
  stage: triage
  before_script:
    - npm install -g gitlab-bta
    - gitlab-bta --version
    - gitlab-bta --help

dry-run:
  extends: .triage
  script:
    - gitlab-bta --dry-run --host-url="http://gitlab.subdomain.fr" --token $API_TOKEN --source-id="1" --policies-file ./triage-policies.js
  when: manual

run:
  extends: .triage
  script:
    - gitlab-bta --host-url="http://gitlab.subdomain.fr" --token $API_TOKEN --source-id="1" --policies-file ./triage-policies.js
  only:
    - schedules

Policies file

Each rule is defined in a policies.js file. Written in JS, it allows you to make some computed properties.

module.exports = {
    resource_rules: {
        merge_requests: {
            rules: [{
                name: "No Bug label",
                conditions: {
                    state: "opened",
                },
                filters: [{
                    name: "No Bug label",
                    filter: function (resource) {
                        return !resource.labels.includes("Bug");
                    },
                }],
                actions: [{
                    name: "label",
                    value: "Status: to complete",
                },{
                    name: "comment",
                    value:  "Hey @{{author.username}}, there is a problem here!",
                }],
            }],
        },
    },
};

Name

You can define a name for each rule making more obvious what the rule do.

Conditions

Conditions are the parameters used to search in the GitLab API :

conditions: {
    state: "opened", // will get only resources opened
    labels: "none", // without any label
},

Additional information

If you need to use information that are only return with the resource detail endpoint (/api/v4/projects/1/issues/1 for example), add additionnal_infos: true to the rule.
When this parameter is present, the GitLab BTA will get all the resources by calling the detail endpoint for each resource found with the passed conditions.
Then you will be able to use some additional information like diverged_commits_count in the filter and actions parts.
Be aware that the rule treatment will take more longer as it call the API for each founded resources.

name: "Too diverged",
additionnal_infos: true,
conditions: {
    state: "opened",
    wip: "no",
    include_diverged_commits_count: true, // this parameter will only be used for the detail API call
},
filters: [{
    name: "Too diverged",
    filter: function (resource) {
        return resource.diverged_commits_count < 50;
    },
}],
actions: [{
    name: "thread",
    value: `{{source_branch}} is too far from {{target_branch}} ({{diverged_commits_count}} commits).`,
}

Filters

You can add somme additional filters, impossible to do with the API. Those are function taking a resource as input and returning true to keep it or false to filter it.

filters: [{
    name: "Already pointed",
    filter: function (resource) {
        return !resource.labels.includes("Status: Stale");
    },
}],

Actions

In actions part, you can define some actions to do.

Label

Add a label to the resource.

actions: [{
    name: "label",
    value: "Status: Stale",
}],

Unlabel

Remove a label from a resource.

actions: [{
    name: "unlabel",
    value: "Status: Stale",
}],

Comment

Add a comment to a resource. You can use the quick actions (like /cc). You can use the resource data in the comment with mustache.

actions: [{
    name: "comment",
    value: `Hey @{{author.username}}, there is a problem here!`,
}],

Thread

Add a thread (or discussion) to a resource. Adding a thread to an MR can block it if you configured your project like this. You can use the resource data in the thread with mustache.

actions: [{
    name: "thread",
    value: `Hey @{{author.username}}, there is a problem here!`,
}],

Update

Update a resource. You can update all the data available in the PUT endpoint for that resource (doc for issues and doc for MRs).

actions: [{
    name: "update",
    value: {
        title: "New title",
    },
}],

Close

Close a resource

actions: [{
    name: "close",
}],