Socket
Socket
Sign inDemoInstall

gitlab-bta

Package Overview
Dependencies
31
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    gitlab-bta

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.


Version published
Weekly downloads
7
decreased by-46.15%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

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",
}],

Keywords

FAQs

Last updated on 26 May 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc