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 🙏

© 2026 – Pkg Stats / Ryan Hefner

glab-tool

v1.0.5

Published

GitLab Extended CLI Tool - A multi-purpose GitLab utility CLI

Downloads

163

Readme

glab-tool - GitLab Extended CLI Tool

一个多功能的 GitLab 命令行工具集。

功能特性

  • 列出分支 - 显示项目所有分支及其详细信息(创建日期、作者、保护状态)
  • 智能清理 - 清理已合并或已关闭的合并请求对应的源分支
  • 交互式选择 - 使用 inquirer 进行交互式分支选择
  • 按状态分组 - 分支按 "已合并" 和 "已关闭" 分组展示
  • 干运行模式 - 预览将删除的分支而不实际执行
  • 强制删除 - 支持强制删除受保护分支
  • 本地分支清理 - 可选同时删除本地对应的 Git 分支
  • 通配符支持 - 目标分支支持通配符匹配(如 release/*

安装

npm install -g glab-tool

快速开始

  1. 创建配置文件 .glabrc
gitlab_url=https://gitlab.example.com/api/v4
gitlab_token=your_access_token
project_id=your_project_id
  1. 列出所有分支:
glabx list
  1. 清理分支(交互式选择):
glabx clean

使用说明

全局选项

  • --config <file>: 配置文件路径(默认: .glabrc

命令

glabx list

列出 GitLab 项目的所有分支。

glabx list

输出示例:

Found 15 branches:
+-------------------+--------------+------------------+-----------+
| Branch            | Created Date | Author           | Protected |
+-------------------+--------------+------------------+-----------+
| main              | 2024-01-15   | John Doe         | Yes       |
| feature/user-auth | 2024-02-20   | Jane Smith       | No        |
| bugfix/login      | 2024-02-22   | Bob Wilson       | No        |
+-------------------+--------------+------------------+-----------+

glabx clean

清理目标分支的已合并/已关闭合并请求对应的源分支。

glabx clean [options]

选项:

  • -t, --target <branch>: 目标分支(默认: main),支持通配符如 release/*
  • -f, --force: 强制删除受保护分支(远程)和未合并分支(本地)
  • -d, --dry-run: 预览模式,显示将删除的分支但不实际删除
  • -l, --local: 同时删除本地对应的 Git 分支

使用示例:

# 清理 targeting main 分支的分支(仅远程)
glabx clean --target main

# 同时删除远程和本地分支
glabx clean --target main --local

# 预览将删除的分支(包括本地分支检查)
glabx clean --target main --local --dry-run

# 强制删除(包括受保护的远程分支和未合并的本地分支)
glabx clean --target main --local --force

# 使用通配符匹配多个目标分支
glabx clean --target release/*

# 交互式选择(无参数)
glabx clean

关于 --local 说明:

  • 仅在当前目录是 Git 仓库且分支存在时才会删除本地分支
  • 默认使用 git branch -d 安全删除(仅删除已合并的分支)
  • 配合 --force 使用 git branch -D 强制删除(即使分支未合并)
  • dry-run 模式下会显示 [local exists] 标识表示本地有对应分支

配置

支持三种配置方式(优先级从高到低):

1. 配置文件 .glabrc

# GitLab API 地址
gitlab_url=https://gitlab.example.com/api/v4

# GitLab 访问令牌
gitlab_token=glpat-xxxxxxxxxxxx

# 项目 ID 或路径(如 group/project)
project_id=123

2. 环境变量

export GITLAB_URL=https://gitlab.example.com/api/v4
export GITLAB_TOKEN=glpat-xxxxxxxxxxxx
export PROJECT_ID=123

3. 命令行参数

(当前版本通过配置文件或环境变量配置)

技术栈

  • Node.js >= 18.0.0
  • Commander ^13.1.0 - CLI 命令解析
  • Axios ^1.6.0 - GitLab API 客户端
  • Inquirer ^9.2.12 - 交互式提示

项目结构

git-clean/
├── index.js              # 主入口,CLI 命令定义
├── package.json
├── src/
│   ├── list.js           # 列出分支功能
│   └── cleanup.js        # 清理分支功能
└── README.md

架构说明

CLI 层 (index.js)
    ↓
业务层 (list.js / cleanup.js)
    ↓
工具层 (配置读取、API 调用)
    ↓
外部层 (GitLab API、配置文件)

数据流向

列出分支流程

  1. 读取配置(文件 → 环境变量)
  2. 创建 GitLab API 客户端
  3. 分页获取所有分支
  4. 对每个分支获取最后提交信息
  5. 格式化输出表格

清理分支流程

  1. 读取配置
  2. 获取目标分支的已合并/已关闭 MR
  3. 获取当前存在的分支
  4. 过滤出可清理的分支
  5. 交互式选择 → 确认 → 删除

开发

# 克隆项目
git clone <repo>
cd git-clean

# 安装依赖
npm install

# 本地运行
node index.js list
node index.js clean

许可证

MIT