xanzy/go-gitlab

GitHub: xanzy/go-gitlab

GitLab 官方认可的 Go 语言 API 客户端 SDK,现已迁移至 GitLab 官方仓库,用于在 Go 程序中以统一方式调用 GitLab V4 API。

Stars: 2430 | Forks: 924

此仓库已归档,因为其开发工作已转移至 GitLab! # go-gitlab(已废弃) 🚧 **项目已迁移至 https://gitlab.com/gitlab-org/api/client-go** 🚧 此包 `github.com/xanzy/go-gitlab` 已被移动至 [`gitlab.com/gitlab-org/api/client-go`](https://gitlab.com/gitlab-org/api/client-go)。 该项目将继续作为一个主要由社区维护的项目, 详情请见[这里](https://gitlab.com/gitlab-org/client.go/-/blob/main/README.md#maintenance)。 **参考**: - [GitLab 项目](https://gitlab.com/gitlab-org/api/client-go) - [问题追踪器](https://gitlab.com/gitlab-org/api/client-go/-/issues) ## 迁移步骤 - 在您的代码库中将 `github.com/xanzy/go-gitlab` 替换为 `gitlab.com/gitlab-org/api/client-go`。 - 搞定 🎉 - *(代码完全向后兼容,预计不会有破坏性更改)*
原 README 内容 一个 GitLab API 客户端,使 Go 程序能够以简单且统一的方式与 GitLab 进行交互 [![Build Status](https://static.pigsec.cn/wp-content/uploads/repos/cas/88/882794e10e222c69d7360ac780bce8f776476765d405f00e1a9692c84c9e08da.svg)](https://github.com/xanzy/go-gitlab/actions?workflow=Lint%20and%20Test) [![Sourcegraph](https://sourcegraph.com/github.com/xanzy/go-gitlab/-/badge.svg)](https://sourcegraph.com/github.com/xanzy/go-gitlab?badge) [![GoDoc](https://godoc.org/github.com/xanzy/go-gitlab?status.svg)](https://godoc.org/github.com/xanzy/go-gitlab) [![Go Report Card](https://goreportcard.com/badge/github.com/xanzy/go-gitlab)](https://goreportcard.com/report/github.com/xanzy/go-gitlab) [![Coverage](https://static.pigsec.cn/wp-content/uploads/repos/cas/8f/8f0b3e1bc1b57fc4fb974b6dc379613a080fd0dd725bfbf559adecba7d8e2da8.svg)](https://raw.githack.com/wiki/xanzy/go-gitlab/coverage.html) ## 注意 Release v0.6.0(发布于 25-08-2017)不再支持旧版的 V3 GitLab API。如果您需要 V3 支持,请使用 `f-api-v3` 分支。此版本包含一些向后不兼容的更改,这些更改是为了全面支持 V4 GitLab API 所必需的。 ## 覆盖范围 此 API 客户端包涵盖了大部分现有的 GitLab API 调用,并会定期更新以添加新的和/或缺失的 endpoint。目前支持以下服务: - [x] Applications - [x] Award Emojis - [x] Branches - [x] Broadcast Messages - [x] Commits - [x] Container Registry - [x] Custom Attributes - [x] Dependency List Export - [x] Deploy Keys - [x] Deployments - [x] Discussions(线程评论) - [x] Environments - [x] Epic Issues - [x] Epics - [x] Error Tracking - [x] Events - [x] Feature Flags - [x] Geo Nodes - [x] Generic Packages - [x] GitLab CI Config Templates - [x] Gitignores Templates - [x] Group Access Requests - [x] Group Issue Boards - [x] Group Members - [x] Group Milestones - [x] Group Wikis - [x] Group-Level Variables - [x] Groups - [x] Instance Clusters - [x] Invites - [x] Issue Boards - [x] Issues - [x] Jobs - [x] Keys - [x] Labels - [x] License - [x] Markdown - [x] Merge Request Approvals - [x] Merge Requests - [x] Namespaces - [x] Notes(评论) - [x] Notification Settings - [x] Open Source License Templates - [x] Packages - [x] Pages - [x] Pages Domains - [x] Personal Access Tokens - [x] Pipeline Schedules - [x] Pipeline Triggers - [x] Pipelines - [x] Plan limits - [x] Project Access Requests - [x] Project Badges - [x] Project Clusters - [x] Project Import/export - [x] Project Members - [x] Project Milestones - [x] Project Repository Storage Moves - [x] Project Snippets - [x] Project Vulnerabilities - [x] Project-Level Variables - [x] Projects(包括设置 Webhooks) - [x] Protected Branches - [x] Protected Environments - [x] Protected Tags - [x] Repositories - [x] Repository Files - [x] Repository Submodules - [x] Runners - [x] Search - [x] Services - [x] Settings - [x] Sidekiq Metrics - [x] System Hooks - [x] Tags - [x] Todos - [x] Topics - [x] Users - [x] Validate CI Configuration - [x] Version - [x] Wikis ## 用法 ``` import "github.com/xanzy/go-gitlab" ``` 构建一个新的 GitLab 客户端,然后使用该客户端上的各种服务来访问 GitLab API 的不同部分。例如,列出所有用户: ``` git, err := gitlab.NewClient("yourtokengoeshere") if err != nil { log.Fatalf("Failed to create client: %v", err) } users, _, err := git.Users.ListUsers(&gitlab.ListUsersOptions{}) ``` 有一些 `With...` 选项函数可用于自定义 API 客户端。例如,设置自定义的 base URL: ``` git, err := gitlab.NewClient("yourtokengoeshere", gitlab.WithBaseURL("https://git.mydomain.com/api/v4")) if err != nil { log.Fatalf("Failed to create client: %v", err) } users, _, err := git.Users.ListUsers(&gitlab.ListUsersOptions{}) ``` 某些 API 方法可以传递可选参数。例如,列出用户 "svanharmelen" 的所有项目: ``` git := gitlab.NewClient("yourtokengoeshere") opt := &gitlab.ListProjectsOptions{Search: gitlab.Ptr("svanharmelen")} projects, _, err := git.Projects.ListProjects(opt) ``` ### 示例 [示例](https://github.com/xanzy/go-gitlab/tree/master/examples)目录包含几个清晰的示例,其中部分也列在了这里: ``` package main import ( "log" "github.com/xanzy/go-gitlab" ) func main() { git, err := gitlab.NewClient("yourtokengoeshere") if err != nil { log.Fatalf("Failed to create client: %v", err) } // Create new project p := &gitlab.CreateProjectOptions{ Name: gitlab.Ptr("My Project"), Description: gitlab.Ptr("Just a test project to play with"), MergeRequestsAccessLevel: gitlab.Ptr(gitlab.EnabledAccessControl), SnippetsAccessLevel: gitlab.Ptr(gitlab.EnabledAccessControl), Visibility: gitlab.Ptr(gitlab.PublicVisibility), } project, _, err := git.Projects.CreateProject(p) if err != nil { log.Fatal(err) } // Add a new snippet s := &gitlab.CreateProjectSnippetOptions{ Title: gitlab.Ptr("Dummy Snippet"), FileName: gitlab.Ptr("snippet.go"), Content: gitlab.Ptr("package main...."), Visibility: gitlab.Ptr(gitlab.PublicVisibility), } _, _, err = git.ProjectSnippets.CreateSnippet(project.ID, s) if err != nil { log.Fatal(err) } } ``` 有关 go-gitlab 的完整用法,请查看完整的[包文档](https://godoc.org/github.com/xanzy/go-gitlab)。 ## 待办事项 - 这个包目前最需要的就是测试 :disappointed: ## 问题 - 如果您遇到问题:请在[问题追踪器](https://github.com/xanzy/go-gitlab/issues)上报告 ## 作者 Sander van Harmelen () ## 贡献 随时欢迎您的贡献。有关更多信息,请查看[贡献指南](https://github.com/xanzy/go-gitlab/blob/master/CONTRIBUTING.md) ## 许可证 基于 Apache License, Version 2.0(“许可证”)授权;除非遵守许可证,否则您不得使用此文件。您可以在 获取许可证副本
标签:API客户端, EVTX分析, GitLab, Go, PPID欺骗, Ruby工具, SOC Prime, 开发工具, 日志审计