Froggit-Go is a Go library, allowing to perform actions on VCS providers

Froggit-Go

Froggit-Go is a Go library, allowing to perform actions on VCS providers. Currently supported providers are: GitHub, Bitbucket Server, Bitbucket Cloud, and GitLab.

Project status

Test Coverage Status Mentioned in Awesome Go Go Report Card

Usage

VCS Clients

Create Clients

GitHub

GitHub api v3 is used

// The VCS provider. Cannot be changed.
vcsProvider := vcsutils.GitHub
// API endpoint to GitHub. Leave empty to use the default - https://api.github.com
apiEndpoint := "https://github.example.com"
// Access token to GitHub
token := "secret-github-token"
// Logger
logger := log.Default()

client, err := vcsclient.NewClientBuilder(vcsProvider).ApiEndpoint(apiEndpoint).Token(token).Build()
GitLab

GitLab api v4 is used.

// The VCS provider. Cannot be changed.
vcsProvider := vcsutils.GitLab
// API endpoint to GitLab. Leave empty to use the default - https://gitlab.com
apiEndpoint := "https://gitlab.example.com"
// Access token to GitLab
token := "secret-gitlab-token"
// Logger
logger := log.Default()

client, err := vcsclient.NewClientBuilder(vcsProvider).ApiEndpoint(apiEndpoint).Token(token).Build()
Bitbucket Server

Bitbucket api 1.0 is used.

// The VCS provider. Cannot be changed.
vcsProvider := vcsclient.BitbucketServer
// API endpoint to Bitbucket server. Typically ends with /rest.
apiEndpoint := "https://git.acme.com/rest"
// Access token to Bitbucket
token := "secret-bitbucket-token"
// Logger
logger := log.Default()

client, err := vcsclient.NewClientBuilder(vcsProvider).ApiEndpoint(apiEndpoint).Token(token).Build()
Bitbucket Cloud

Bitbucket cloud api version 2.0 is used and the version should be added to the apiEndpoint.

// The VCS provider. Cannot be changed.
vcsProvider := vcsutils.BitbucketCloud
// API endpoint to Bitbucket cloud. Leave empty to use the default - https://api.bitbucket.org/2.0
apiEndpoint := "https://bitbucket.example.com"
// Bitbucket username
username := "bitbucket-user"
// Password or Bitbucket "App Password'
token := "secret-bitbucket-token"
// Logger
logger := log.Default()

client, err := vcsclient.NewClientBuilder(vcsProvider).ApiEndpoint(apiEndpoint).Username(username).Token(token).Build()

Test Connection

// Go context
ctx := context.Background()

err := client.TestConnection(ctx)

List Repositories

// Go context
ctx := context.Background()

repositories, err := client.ListRepositories(ctx)

List Branches

// Go context
ctx := context.Background()
// Organization or username
owner := "jfrog"
// VCS repository
repository := "jfrog-cli"

repositoryBranches, err := client.ListBranches(ctx, owner, repository)

Download Repository

// Go context
ctx := context.Background()
// Organization or username
owner := "jfrog"
// VCS repository
repository := "jfrog-cli"
// Repository branch
branch := "master"
// Local path in the file system
localPath := "/Users/frogger/code/jfrog-cli"

repositoryBranches, err := client.DownloadRepository(ctx, owner, repository, branch, localPath)

Create Webhook

// Go context
ctx := context.Background()
// Organization or username
owner := "jfrog"
// The event to watch
webhookEvent := vcsutils.Push
// VCS repository
repository := "jfrog-cli"
// Optional - Webhooks on branches are supported only on GitLab
branch := ""
// The URL to send the payload upon a webhook event
payloadURL := "https://acme.jfrog.io/integration/api/v1/webhook/event"

// token - A token used to validate identity of the incoming webhook.
// In GitHub and Bitbucket server the token verifies the sha256 signature of the payload.
// In GitLab and Bitbucket cloud the token compared to the token received in the incoming payload.
id, token, err := client.CreateWebhook(ctx, owner, repository, branch, "https://jfrog.com", webhookEvent)

Update Webhook

// Go context
ctx := context.Background()
// Organization or username
owner := "jfrog"
// VCS repository
repository := "jfrog-cli"
// Optional - Webhooks on branches are supported only on GitLab
branch := ""
// The URL to send the payload upon a webhook event
payloadURL := "https://acme.jfrog.io/integration/api/v1/webhook/event"
// A token to validate identity of the webhook, created by CreateWebhook command
token := "abc123"
// The webhook ID returned by the CreateWebhook API, which created this webhook
webhookID := "123"
// The event to watch
webhookEvent := vcsutils.PrCreated

err := client.UpdateWebhook(ctx, owner, repository, branch, "https://jfrog.com", token, webhookID, webhookEvent)

Delete Webhook

// Go context
ctx := context.Background()
// Organization or username
owner := "jfrog"
// VCS repository
repository := "jfrog-cli"
// The webhook ID returned by the CreateWebhook API, which created this webhook
webhookID := "123"

err := client.DeleteWebhook(ctx, owner, repository, webhookID)

Set Commit Status

// Go context
ctx := context.Background()
// One of Pass, Fail, Error, or InProgress
commitStatus := vcsclient.Pass
// Organization or username
owner := "jfrog"
// VCS repository
repository := "jfrog-cli"
// Branch or commit or tag on GitHub and GitLab, commit on Bitbucket
ref := "5c05522fecf8d93a11752ff255c99fcb0f0557cd"
// Title of the commit status
title := "Xray scanning"
// Description of the commit status
description := "Run JFrog Xray scan"
// URL leads to the platform to provide more information, such as Xray scanning results
detailsURL := "https://acme.jfrog.io/ui/xray-scan-results-url"

err := client.SetCommitStatus(ctx, commitStatus, owner, repository, ref, title, description, detailsURL)
Create Pull Request
// Go context
ctx := context.Background()
// Organization or username
owner := "jfrog"
// VCS repository
repository := "jfrog-cli"
// Source pull request branch
sourceBranch := "dev"
// Target pull request branch
targetBranch := "main"
// Pull request title
title := "Pull request title"
// Pull request description
description := "Pull request description"

err := client.CreatePullRequest(ctx, owner, repository, sourceBranch, targetBranch, title, description string)

Get Latest Commit

// Go context
ctx := context.Background()
// Organization or username
owner := "jfrog"
// VCS repository
repository := "jfrog-cli"
// VCS branch
branch := "dev"

// Commit information of the latest commit
commitInfo, err := client.GetLatestCommit(ctx, owner, repository, branch)

Get Commit By SHA

// Go context
ctx := context.Background()
// Organization or username
owner := "jfrog"
// VCS repository
repository := "jfrog-cli"
// SHA-1 hash of the commit
sha := "abcdef0123abcdef4567abcdef8987abcdef6543"

// Commit information of requested commit
commitInfo, err := client.GetCommitBySha(ctx, owner, repository, sha)

Add Public SSH Key

// Go context
ctx := context.Background()
// Organization or username
owner := "jfrog"
// VCS repository
repository := "jfrog-cli"
// An identifier for the key
keyName := "my ssh key"
// The public SSH key
publicKey := "ssh-rsa AAAA..."
// Access permission of the key: vcsclient.Read or vcsclient.ReadWrite
permission = vcsclient.Read

// Add a public SSH key to a repository
err := client.AddSshKeyToRepository(ctx, owner, repository, keyName, publicKey, permission)

Get Repository Info

// Go context
ctx := context.Background()
// Organization or username
owner := "jfrog"
// VCS repository
repository := "jfrog-cli"

// Get information about repository
repoInfo, err := client.GetRepositoryInfo(ctx, owner, repository)

Webhook Parser

// Go context
ctx := context.Background()
// Token to authenticate incoming webhooks. If empty, signature will not be verified.
// The token is a random key generated in the CreateWebhook command.
token := "abc123"
// The HTTP request of the incoming webhook
request := http.Request{}
// The VCS provider
provider := vcsutils.GitHub

webhookInfo, err := webhookparser.ParseIncomingWebhook(provider, token, request)
Comments
  • Fix for pagination issues in Gitlab list repositories.

    Fix for pagination issues in Gitlab list repositories.

    • [x] All tests passed. If this feature is not already covered by the tests, I added new tests.

    • [x] I used go fmt ./... for formatting the code before submitting the pull request.

    • [x] This feature is included on all supported VCS providers - GitHub, Bitbucket cloud, Bitbucket Server, and GitLab.


    Issue Description -

    Github list repositories API does not iterate through all the pages available in the remote repository. And it also repeats the repository names when there is more than one page.

    Fix Details -

    The problem here is that the page index variable in the library is initialized as zero, so the first-page request goes as https://api.github.com/user/repos?page=0 followed by https://api.github.com/user/repos?page=1. Both these requests are treated as a request for Page 1 by the GitHub API, and will return the same result set.

  • set repo/owner in different fields for webhookinfo

    set repo/owner in different fields for webhookinfo

    This returns the repo owner and name as distinct field, and also fixes some inconsistencies with GetRepositories where we would return the slug and the webhook would return the name

  • GetCloneInfo - return info to clone repository

    GetCloneInfo - return info to clone repository

    Each VCS provides clone functionality in one or another way. Currently we are using SSH and HTTPS protocols to do the clone. If protocol is not supported the returned value will be empty.

    I have read the CLA Document and I hereby sign the CLA

  • Concurrency issue with bitbucket

    Concurrency issue with bitbucket

    On this file https://github.com/jfrog/froggit-go/blob/40ca96b66fb0aef79adf9d8814f40af7682b7552/vcsclient/bitbucketcloud.go#L23 We get the url via environment variable so if we need multiple bitbucket call in parallel, they might use a wrong value

  • Fix for pagination issues in GitHub list repositories

    Fix for pagination issues in GitHub list repositories

    • [x] All tests passed. If this feature is not already covered by the tests, I added new tests.
    • [x] I used go fmt ./... for formatting the code before submitting the pull request.
    • [x] This feature is included on all supported VCS providers - GitHub, Bitbucket cloud, Bitbucket server, and GitLab.

    Issue Description -

    Github list repositories API does not iterate through all the pages available in the remote repository. And it also repeats the repository names when there is more than one page.

    Fix Details -

    The problem here is that the page index variable in the library is initialized as zero, so the first-page request goes as https://api.github.com/user/repos?page=0 followed by https://api.github.com/user/repos?page=1. Both these requests are treated as a request for Page 1 by the GitHub API, and will return the same result set.

  • go-bitbucket uses os.Exit

    go-bitbucket uses os.Exit

    Froggit-go uses github.com/ktrysmt/go-bitbucket but this library may, under some circumstances, kill the process using os.Exit(9).

    For instance, in webhooks.go:

    	data, err := json.Marshal(body)
    	if err != nil {
    		pp.Println(err)
    		os.Exit(9)
    	}
    

    Possible fixes:

    • Drop the library
    • Or fork and open a PR on the library
  • Add Logger and logs

    Add Logger and logs

    • [x] All tests passed. If this feature is not already covered by the tests, I added new tests.
    • [x] I used go fmt ./... for formatting the code before submitting the pull request.
    • [x] This feature is included on all supported VCS providers - GitHub, Bitbucket cloud, Bitbucket server, and GitLab.

  • Test PR - Please ignore

    Test PR - Please ignore

    • [ ] All tests passed. If this feature is not already covered by the tests, I added new tests.
    • [ ] I used go fmt ./... for formatting the code before submitting the pull request.
    • [ ] This feature is included on all supported VCS providers - GitHub, Bitbucket cloud, Bitbucket server, and GitLab.

  • 30 - panic if push has no commits

    30 - panic if push has no commits

    GitLab provider panics if push event has no Commits provided. Fix it by checking presents of at least one commit object before getting a timestamp.

    • [x] All tests passed. If this feature is not already covered by the tests, I added new tests.
    • [x] I used go fmt ./... for formatting the code before submitting the pull request.
    • [-] This feature is included on all supported VCS providers - GitHub, Bitbucket cloud, Bitbucket server, and GitLab.

    Closes: https://github.com/jfrog/froggit-go/issues/30

  • GitLabWebhook.parsePushEvent method panics

    GitLabWebhook.parsePushEvent method panics

    Describe the bug Method parsePushEvent of the GitLabWebhook type panics in case there are no commits related to the event. The actual code that causes the issue Timestamp: event.Commits[0].Timestamp.Local().Unix(),

    Expected behavior No panic to be generated.

    • Froggit-Go version: https://github.com/jfrog/froggit-go/releases/tag/v1.0.0
    • Operating system:

    Additional context Add any other context about the problem here.

  • Add DownloadFileFromRepo API to GitHub and GitLab

    Add DownloadFileFromRepo API to GitHub and GitLab

    • [x] All tests passed. If this feature is not already covered by the tests, I added new tests.
    • [x] I used go fmt ./... for formatting the code before submitting the pull request.
    • [x] This feature is included on all supported VCS providers - GitHub, Bitbucket cloud, Bitbucket server, and GitLab.

  • How to interact with and manage the remote repo or vcs provider via ssh key instead of user/pass?

    How to interact with and manage the remote repo or vcs provider via ssh key instead of user/pass?

    Cool library! Got a question not addressed in the docs or the source…

    Setup: I use Bitbucket cloud. Seeing that the example requires a username and password for interacting with the “remote”. Seeing there is a way to add ash keys to repos, which seems to be configuring some access on the “remote”.

    Question: Curious if there is a way to interact with the “remote” via a specific ssh key that is present on my computer instead of username and password. Not seeing that reflected in the documentation.

    Also, there is a comment typo in the file defining how bitbucket cloud will fulfill the interface. List open pull requests seems to have the same comment as create pull request.

    Thanks!

  • Typed Errors

    Typed Errors

    Froggit is a facade over different git providers and should provide typed error messages. The user of the library should receive clear errors and not have to have knowledge of the internal structure of each git providers errors.

    Froggit should return errors such as NotFound, Unauthorized, Forbidden, Bad Request, InternalServerError where possible.

  • Timestamp calculation results in different units (depends on git provider)

    Timestamp calculation results in different units (depends on git provider)

    timestamp calculation sometimes in seconds (e.g. bitbucket cloud) and sometimes in milliseconds (e.g. bitbucket server). we should unify this behaviour.

  • Fail to parse date when testing a webhook with Gitlab

    Fail to parse date when testing a webhook with Gitlab

    When hitting the "test" button of a webhook in Gitlab, 14.4 the date format is slightly different and Froggit-Go is failing with the following error message: parsing time "2021-11-30T08:52:57.746Z" as "2006-01-02 15:04:05 MST": cannot parse "T08:52:57.746Z" as " "

  • http. RoundTripper is not re-used

    http. RoundTripper is not re-used

    For the bitbucketserver and github vcsclient(s) the http.RoundTripper is not re-used, but created for each new request if client.vcsInfo.Token is provided.
    This can cause an issue because connections acquire file descriptors and won't be released immediately after http.Client garbage collection, please see https://golang.org/src/net/http/transport.go#L68

  • Input validation

    Input validation

    Required parameters are not checked before sending request to different providers. It might be nice to check the parameters and return appropriate errors.

Maintain a lower-bitrate copy of a music library in sync with the main copy.

msync Maintain a lower-bitrate copy of your music library, in sync with the main copy.

Mar 6, 2022
Golang library to act on structure fields at runtime. Similar to Python getattr(), setattr(), hasattr() APIs.

go-attr Golang library to act on structure fields at runtime. Similar to Python getattr(), setattr(), hasattr() APIs. This package provides user frien

Dec 16, 2022
Go library for HTTP content type negotiation

Content-Type support library for Go This library can be used to parse the value Content-Type header (if one is present) and select an acceptable media

Jul 10, 2022
A tool and library for using structural regular expressions.

Structural Regular Expressions sregx is a package and tool for using structural regular expressions as described by Rob Pike (link).

Dec 7, 2022
A super simple Lodash like utility library with essential functions that empowers the development in Go
A super simple Lodash like utility library with essential functions that empowers the development in Go

A simple Utility library for Go Go does not provide many essential built in functions when it comes to the data structure such as slice and map. This

Jan 4, 2023
go-sysinfo is a library for collecting system information.

go-sysinfo go-sysinfo is a library for collecting system information. This includes information about the host machine and processes running on the ho

Dec 26, 2022
Molecule is a Go library for parsing protobufs in an efficient and zero-allocation manner

Molecule Molecule is a Go library for parsing protobufs in an efficient and zero-allocation manner. The API is loosely based on this excellent Go JSON

Jan 5, 2023
A Go (golang) library for parsing and verifying versions and version constraints.

go-version is a library for parsing versions and version constraints, and verifying versions against a set of constraints. go-version can sort a collection of versions properly, handles prerelease/beta versions, can increment versions, etc.

Jan 9, 2023
A library for parsing ANSI encoded strings
 A library for parsing ANSI encoded strings

Go ANSI Parser converts strings with ANSI escape codes into a slice of structs that represent styled text

Sep 20, 2022
go generate based graphql server library
go generate based graphql server library

gqlgen What is gqlgen? gqlgen is a Go library for building GraphQL servers without any fuss. gqlgen is based on a Schema first approach — You get to D

Dec 29, 2022
This is Go library for building GraphQL client with gqlgen

gqlgenc What is gqlgenc ? This is Go library for building GraphQL client with gqlgen Motivation Now, if you build GraphQL api client for Go, have choi

Jan 7, 2023
A library for diffing golang structures

Diff A library for diffing golang structures and values. Utilizing field tags and reflection, it is able to compare two structures of the same type an

Dec 29, 2022
Go library for decoding generic map values into native Go structures and vice versa.

mapstructure mapstructure is a Go library for decoding generic map values to structures and vice versa, while providing helpful error handling. This l

Dec 28, 2022
🍀 Go basic library. || Go语言基础库
🍀 Go basic library. || Go语言基础库

Go语言基础库 工程目录说明 pkg/ ...... 源码包 |-- bininfo/ ...... 将编译时源码的git版本信息(当前commit log的sha值和commit message),编译时间,Go版本,平台打入程序中

Dec 28, 2022
A well tested and comprehensive Golang statistics library package with no dependencies.

Stats - Golang Statistics Package A well tested and comprehensive Golang statistics library / package / module with no dependencies. If you have any s

Dec 30, 2022
go-sundheit:A library built to provide support for defining service health for golang services
go-sundheit:A library built to provide support for defining service health for golang services

A library built to provide support for defining service health for golang services. It allows you to register async health checks for your dependencies and the service itself, and provides a health endpoint that exposes their status.

Dec 27, 2022
Go library that provides fuzzy string matching optimized for filenames and code symbols in the style of Sublime Text, VSCode, IntelliJ IDEA et al.
Go library that provides fuzzy string matching optimized for filenames and code symbols in the style of Sublime Text, VSCode, IntelliJ IDEA et al.

Go library that provides fuzzy string matching optimized for filenames and code symbols in the style of Sublime Text, VSCode, IntelliJ IDEA et al. This library is external dependency-free. It only depends on the Go standard library.

Dec 27, 2022
Helper library for full uint64 randomness, pool backed for efficient concurrency

fastrand64-go Helper library for full uint64 randomness, pool backed for efficient concurrency Inspired by https://github.com/valyala/fastrand which i

Dec 5, 2021
Cogger is a standalone binary and a golang library that reads an internally tiled geotiff

Cogger is a standalone binary and a golang library that reads an internally tiled geotiff (optionally with overviews and masks) and rewrites it

Dec 12, 2022