Bitzsoft.Integrations.ProjectManagement.GitLab
1.0.4
dotnet add package Bitzsoft.Integrations.ProjectManagement.GitLab --version 1.0.4
NuGet\Install-Package Bitzsoft.Integrations.ProjectManagement.GitLab -Version 1.0.4
<PackageReference Include="Bitzsoft.Integrations.ProjectManagement.GitLab" Version="1.0.4" />
<PackageVersion Include="Bitzsoft.Integrations.ProjectManagement.GitLab" Version="1.0.4" />
<PackageReference Include="Bitzsoft.Integrations.ProjectManagement.GitLab" />
paket add Bitzsoft.Integrations.ProjectManagement.GitLab --version 1.0.4
#r "nuget: Bitzsoft.Integrations.ProjectManagement.GitLab, 1.0.4"
#:package Bitzsoft.Integrations.ProjectManagement.GitLab@1.0.4
#addin nuget:?package=Bitzsoft.Integrations.ProjectManagement.GitLab&version=1.0.4
#tool nuget:?package=Bitzsoft.Integrations.ProjectManagement.GitLab&version=1.0.4
Bitzsoft.Integrations.ProjectManagement.GitLab
GitLab REST API v4 项目与工单连接器实现。遵循项目管理通用抽象规范,实现 IProjectManagementService 接口与专属的 IGitLabProjectManagementService 扩展接口。
功能特性
- 通用契约对齐:实现
IProjectManagementService抽象规范,统一映射 GitLab Projects 与 Issues,支持创建、查询详情、更新属性、完成与状态过滤。 - 双模鉴权机制:原生支持
PRIVATE-TOKEN请求头鉴权与标准 OAuth2Bearer令牌鉴权。 - 企业私有部署支持:完美兼容 GitLab CE(社区版)与 GitLab EE(企业版)私有化部署,支持自签名 SSL 证书信任配置(
AllowInsecureCertificates)。 - Issue 讨论与 Notes 协作:支持追加 Issue 讨论笔记/评论(
AddNoteAsync)与列举全部历史 Notes(ListNotesAsync)。 - Issue 状态机转换:专属支持关闭工单(
CloseIssueAsync)与重新打开工单(ReopenIssueAsync)。 - Issue 标签(Labels)自动映射:自动将 GitLab Issue 的全部标签列表(
labels)映射为统一模型的PmTask.Tags,无缝对接下游分类统计与标签过滤。 - 合并请求(Merge Request)检索:支持按项目与状态检索关联的合并请求(
ListMergeRequestsAsync)。 - 工业级弹性韧性:集成 Polly 标准韧性管道(429/503 指数退避重试与熔断保护)及全量出站请求审计日志(
RequestLogging)。
安装
dotnet add package Bitzsoft.Integrations.ProjectManagement.GitLab
<PackageReference Include="Bitzsoft.Integrations.ProjectManagement.GitLab" Version="1.0.0" />
配置
在 appsettings.json 中配置 GitLab 连接器参数:
{
"ProjectManagement": {
"GitLab": {
"BaseUrl": "https://gitlab.com/api/v4",
"AccessToken": "glpat-your-personal-access-token",
"UseBearerAuth": false,
"DefaultProjectId": "my-group/my-project",
"AllowInsecureCertificates": false
}
}
}
配置项说明
| 配置键 | 类型 | 默认值 | 说明 |
|---|---|---|---|
BaseUrl |
string |
https://gitlab.com/api/v4 |
GitLab API v4 基地址。公有云为 https://gitlab.com/api/v4,私有化形如 https://gitlab.corp.internal/api/v4。 |
AccessToken |
string |
"" |
GitLab 访问凭据(Personal Access Token、Project Access Token 或 OAuth2 Bearer)。需具有 api 作用域。 |
UseBearerAuth |
bool |
false |
是否使用 Bearer 认证标头。若为 false,则使用 GitLab 规范的 PRIVATE-TOKEN 标头。 |
DefaultProjectId |
string? |
null |
默认项目标识(支持项目数字 ID 如 12345 或命名空间路径如 my-group/my-project)。 |
AllowInsecureCertificates |
bool |
false |
是否信任企业私有化部署的自签名 SSL 证书。 |
注册服务
支持通过配置源绑定或委托方式进行依赖注入注册:
using Microsoft.Extensions.DependencyInjection;
// 方式 1:通过 IConfiguration 绑定注册(推荐,默认读取 ProjectManagement:GitLab)
services.AddBitzsoftGitLabProjectManagement(configuration);
// 自定义配置节路径:
// services.AddBitzsoftGitLabProjectManagement(configuration, "Integrations:GitLab");
// 方式 2:通过委托手动配置注册
services.AddBitzsoftGitLabProjectManagement(options =>
{
options.BaseUrl = "https://gitlab.com/api/v4";
options.AccessToken = "glpat-your-personal-access-token";
options.DefaultProjectId = "my-group/my-project";
options.UseBearerAuth = false;
options.AllowInsecureCertificates = false;
});
使用示例(通用 IProjectManagementService)
以下代码演示如何在业务类中通过依赖注入使用通用的 IProjectManagementService 契约操作 GitLab Issues:
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Bitzsoft.Integrations.ProjectManagement;
using Bitzsoft.Integrations.ProjectManagement.Dtos;
using TaskStatus = Bitzsoft.Integrations.ProjectManagement.Dtos.TaskStatus;
namespace YourNamespace;
public class GitLabIssueAppService
{
private readonly IProjectManagementService _pmService;
public GitLabIssueAppService(IProjectManagementService pmService)
{
_pmService = pmService;
}
public async Task<PmTask> CreateIssueAsync(
string projectIdOrPath,
string title,
string description,
string? assigneeId = null,
DateTimeOffset? dueDate = null,
CancellationToken cancellationToken = default)
{
var request = new CreateTaskRequest
{
ProjectId = projectIdOrPath,
Name = title,
Description = description,
AssigneeId = assigneeId,
DueDate = dueDate,
Priority = TaskPriority.High
};
return await _pmService.CreateTaskAsync(request, cancellationToken);
}
public async Task<PmTask> GetIssueAsync(
string issueIid,
CancellationToken cancellationToken = default)
{
var task = await _pmService.GetTaskAsync(issueIid, cancellationToken);
// GitLab Issue 关联的全部标签(Labels)已自动提取并映射至 task.Tags
return task;
}
public async Task<List<PmTask>> ListOpenIssuesAsync(
string projectIdOrPath,
CancellationToken cancellationToken = default)
{
var request = new ListTasksRequest
{
ProjectId = projectIdOrPath,
Status = TaskStatus.InProgress,
PageIndex = 1,
PageSize = 25
};
return await _pmService.ListTasksAsync(request, cancellationToken);
}
public async Task<PmResult> CloseIssueAsync(
string issueIid,
CancellationToken cancellationToken = default)
{
return await _pmService.CompleteTaskAsync(issueIid, cancellationToken);
}
}
专有扩展能力(IGitLabProjectManagementService)
当业务需要针对 GitLab 专有能力(如追加讨论 Note、查询全部 Notes 列表、关闭/重开 Issue、检索关联合并请求 Merge Requests)进行操作时,可直接注入专属接口 IGitLabProjectManagementService:
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Bitzsoft.Integrations.ProjectManagement.GitLab;
using Bitzsoft.Integrations.ProjectManagement.GitLab.Dtos;
namespace YourNamespace;
public class GitLabAdvancedWorkflowService
{
private readonly IGitLabProjectManagementService _gitLabService;
public GitLabAdvancedWorkflowService(IGitLabProjectManagementService gitLabService)
{
_gitLabService = gitLabService;
}
public async Task AddDiscussionNoteAsync(
string projectId,
int issueIid,
string noteContent,
CancellationToken cancellationToken = default)
{
await _gitLabService.AddNoteAsync(projectId, issueIid, noteContent, cancellationToken);
}
public async Task<List<GitLabNoteDto>> GetIssueDiscussionsAsync(
string projectId,
int issueIid,
CancellationToken cancellationToken = default)
{
return await _gitLabService.ListNotesAsync(projectId, issueIid, cancellationToken);
}
public async Task ReopenOrCloseIssueAsync(
string projectId,
int issueIid,
bool reopen,
CancellationToken cancellationToken = default)
{
if (reopen)
{
await _gitLabService.ReopenIssueAsync(projectId, issueIid, cancellationToken);
}
else
{
await _gitLabService.CloseIssueAsync(projectId, issueIid, cancellationToken);
}
}
public async Task<List<GitLabMergeRequestDto>> GetOpenedMergeRequestsAsync(
string projectId,
CancellationToken cancellationToken = default)
{
return await _gitLabService.ListMergeRequestsAsync(projectId, "opened", cancellationToken);
}
}
依赖
| 包 | 说明 |
|---|---|
| Bitzsoft.Integrations.ProjectManagement | 项目管理服务统一抽象层 |
| Bitzsoft.Integrations.Core | 公共基座与供应商解析机制 |
| Bitzsoft.Integrations.Compatibility | 多目标框架兼容性工具集 |
| Bitzsoft.Integrations.RequestLogging | 出站请求审计与耗时追踪日志 |
相关包
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 is compatible. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Bitzsoft.Integrations.Compatibility (>= 1.0.4)
- Bitzsoft.Integrations.Core (>= 1.0.4)
- Bitzsoft.Integrations.ProjectManagement (>= 1.0.4)
- Bitzsoft.Integrations.RequestLogging (>= 1.0.4)
- Microsoft.Extensions.Configuration.Abstractions (>= 10.0.10)
- Microsoft.Extensions.Http (>= 10.0.10)
- Microsoft.Extensions.Http.Resilience (>= 10.7.0)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 10.0.10)
-
net5.0
- Bitzsoft.Integrations.Compatibility (>= 1.0.4)
- Bitzsoft.Integrations.Core (>= 1.0.4)
- Bitzsoft.Integrations.ProjectManagement (>= 1.0.4)
- Bitzsoft.Integrations.RequestLogging (>= 1.0.4)
- Microsoft.Extensions.Configuration.Abstractions (>= 5.0.0)
- Microsoft.Extensions.Http (>= 5.0.0)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 5.0.0)
-
net8.0
- Bitzsoft.Integrations.Compatibility (>= 1.0.4)
- Bitzsoft.Integrations.Core (>= 1.0.4)
- Bitzsoft.Integrations.ProjectManagement (>= 1.0.4)
- Bitzsoft.Integrations.RequestLogging (>= 1.0.4)
- Microsoft.Extensions.Configuration.Abstractions (>= 10.0.10)
- Microsoft.Extensions.Http (>= 10.0.10)
- Microsoft.Extensions.Http.Resilience (>= 10.7.0)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 10.0.10)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Bitzsoft.Integrations.ProjectManagement.GitLab:
| Package | Downloads |
|---|---|
|
Bitzsoft.Integrations.ProjectManagement.All
项目管理服务聚合包 — 包含全部供应商实现(Asana / Teambition / Monday / Trello / ONES / PingCode / Yunxiao / GitHub / GitLab / Gitee / JiraCloud / JiraDataCenter / AzureDevOps / Tapd) |
GitHub repositories
This package is not used by any popular GitHub repositories.