go-scm

module
v1.33.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 27, 2023 License: BSD-2-Clause-Patent

README

go-scm

Go Doc

Package scm provides a unified interface to multiple source code management systems including GitHub, GitHub Enterprise, Bitbucket, Bitbucket Server, Gitee, Gitea and Gogs.

Getting Started

Create a GitHub client:

package main

import (
  "git.awesome-for.me/liuzhiguo/go-scm/scm"
  "git.awesome-for.me/liuzhiguo/go-scm/scm/driver/github"
)

func main() {
client := github.NewDefault()
}

Create a GitHub Enterprise client:

import (
  "git.awesome-for.me/liuzhiguo/go-scm/scm"
  "git.awesome-for.me/liuzhiguo/go-scm/scm/driver/github"
)

func main() {
    client, err := github.New("https://github.company.com/api/v3")
}

Create a Bitbucket client:

import (
  "git.awesome-for.me/liuzhiguo/go-scm/scm"
  "git.awesome-for.me/liuzhiguo/go-scm/scm/driver/bitbucket"
)

func main() {
    client, err := bitbucket.New()
}

Create a Bitbucket Server (Stash) client:

import (
  "git.awesome-for.me/liuzhiguo/go-scm/scm"
  "git.awesome-for.me/liuzhiguo/go-scm/scm/driver/stash"
)

func main() {
    client, err := stash.New("https://stash.company.com")
}

Create a Gitea client:

import (
  "git.awesome-for.me/liuzhiguo/go-scm/scm"
  "git.awesome-for.me/liuzhiguo/go-scm/scm/driver/gitea"
)

func main() {
  client, err := gitea.New("https://gitea.company.com")
}

Create a Gitee client:

import (
  "git.awesome-for.me/liuzhiguo/go-scm/scm"
  "git.awesome-for.me/liuzhiguo/go-scm/scm/driver/gitee"
)

func main() {
  client, err := gitee.New("https://gitee.com/api/v5")
}

Authentication

The scm client does not directly handle authentication. Instead, when creating a new client, provide an http.Client that can handle authentication for you. For convenience, this library includes oauth1 and oauth2 implementations that can be used to authenticate requests.

package main

import (
  "git.awesome-for.me/liuzhiguo/go-scm/scm"
  "git.awesome-for.me/liuzhiguo/go-scm/scm/driver/github"
  "git.awesome-for.me/liuzhiguo/go-scm/scm/transport"
  "git.awesome-for.me/liuzhiguo/go-scm/scm/transport/oauth2"
)

func main() {
  client := github.NewDefault()

  // provide a custom http.Client with a transport
  // that injects the oauth2 token.
  client.Client = &http.Client{
    Transport: &oauth2.Transport{
      Source: oauth2.StaticTokenSource(
        &scm.Token{
          Token: "ecf4c1f9869f59758e679ab54b4",
        },
      ),
    },
  }

  // provide a custom http.Client with a transport
  // that injects the private GitLab token through
  // the PRIVATE_TOKEN header variable.
  client.Client = &http.Client{
    Transport: &transport.PrivateToken{
      Token: "ecf4c1f9869f59758e679ab54b4",
    },
  }
}

Usage

The scm client exposes dozens of endpoints for working with repositories, issues, comments, files and more. Please see the godocs to learn more.

Example code to get an issue:

issue, _, err := client.Issues.Find(ctx, "octocat/Hello-World", 1)

Example code to get a list of issues:

opts := scm.IssueListOptions{
  Page:   1,
  Size:   30,
  Open:   true,
  Closed: false,
}

issues, _, err := client.Issues.List(ctx, "octocat/Hello-World", opts)

Example code to create an issue comment:

in := &scm.CommentInput{
  Body: "Found a bug",
}

comment, _, err := client.Issues.CreateComment(ctx, "octocat/Hello-World", 1, in)

Here are some useful links to providers API documentation:

Release procedure

Run the changelog generator.

docker run -it --rm -v "$(pwd)":/usr/local/src/your-app githubchangeloggenerator/github-changelog-generator -u drone -p go-scm -t <secret github token>

You can generate a token by logging into your GitHub account and going to Settings -> Personal access tokens.

Next we tag the PR's with the fixes or enhancements labels. If the PR does not fufil the requirements, do not add a label.

Run the changelog generator again with the future version according to semver.

docker run -it --rm -v "$(pwd)":/usr/local/src/your-app githubchangeloggenerator/github-changelog-generator -u drone -p go-scm -t <secret token> --future-release v1.15.2

Create your pull request for the release. Get it merged then tag the release.

Directories

Path Synopsis
scm
driver/azure
Package azure implements a azure client.
Package azure implements a azure client.
driver/bitbucket
Package bitbucket implements a Bitbucket Cloud client.
Package bitbucket implements a Bitbucket Cloud client.
driver/bitbucket/integration
Package integration implements a Bitbucket Cloud integration tests.
Package integration implements a Bitbucket Cloud integration tests.
driver/gitea
Package gitea implements a Gitea client.
Package gitea implements a Gitea client.
driver/gitee
Package gitee implements a Gitee client.
Package gitee implements a Gitee client.
driver/github
Package github implements a GitHub client.
Package github implements a GitHub client.
driver/gitlab
Package gitlab implements a GitLab client.
Package gitlab implements a GitLab client.
driver/gogs
Package gogs implements a Gogs client.
Package gogs implements a Gogs client.
driver/stash
Package stash implements a Bitbucket Server client.
Package stash implements a Bitbucket Server client.
enrich
Package normalize provides facilities for enriching data structures with missing information.
Package normalize provides facilities for enriching data structures with missing information.
transport
Package transport provides facilities for setting up authenticated http.RoundTripper given credentials and base RoundTripper.
Package transport provides facilities for setting up authenticated http.RoundTripper given credentials and base RoundTripper.
traverse
Package traverse provides facilities for traversing and combining the paginated results.
Package traverse provides facilities for traversing and combining the paginated results.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL