- Notifications
You must be signed in to change notification settings - Fork26
Froggit-Go is a universal Go library, allowing to perform actions on VCS providers.
License
jfrog/froggit-go
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Froggit-Go is a Go library, allowing to perform actions on VCS providers.Currently supported providers are:GitHub,Bitbucket Server,Bitbucket Cloud,Azure Repos andGitLab.
- Froggit-Go
- Project status
- Usage
- VCS Clients
- Create Clients
- Test Connection
- List Repositories
- List App Repositories
- List Branches
- List Pull Request Reviews
- Download Repository
- Create Webhook
- Update Webhook
- Delete Webhook
- Set Commit Status
- Get Commit Status
- Create Pull Request
- Update Pull Request
- Get Pull Request By ID
- List Open Pull Requests
- List Open Pull Requests With Body
- Add Pull Request Comment
- Add Pull Request Review Comments
- List Pull Request Comments
- List Pull Request Review Comments
- Delete Pull Request Comment
- Delete Pull Request Review Comments
- Get Commits
- Get Commits With Options
- Get Latest Commit
- Get Commit By SHA
- List Pull Requests associated with a Commit
- Get List of Modified Files
- Add Public SSH Key
- Get Repository Info
- Get Repository Environment Info
- Create a label
- Get a label
- List Pull Request Labels
- Unlabel Pull Request
- Upload Code Scanning
- Download a File From a Repository
- Create a branch
- Allow workflows on organization
- Add Organization Secret
- Get Repo Collaborators
- Get Repo Teams By Permissions
- Create Or Update Environment
- CommitAndPushFiles
- Merge Pull Request
- Create Pull Request Detailed
- Upload Snapshot To Dependency Graph
- Webhook Parser
- VCS Clients
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.comapiEndpoint:="https://github.example.com"// Access token to GitHubtoken:="secret-github-token"// Logger// [Optional]// Supported logger is a logger that implements the Log interface.// More information - https://github.com/jfrog/froggit-go/blob/master/vcsclient/logger.gologger:=log.Default()client,err:=vcsclient.NewClientBuilder(vcsProvider).ApiEndpoint(apiEndpoint).Token(token).Build()
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.comapiEndpoint:="https://gitlab.example.com"// Access token to GitLabtoken:="secret-gitlab-token"// Logger// [Optional]// Supported logger is a logger that implements the Log interface.// More information - https://github.com/jfrog/froggit-go/blob/master/vcsclient/logger.gologger:=loggerclient,err:=vcsclient.NewClientBuilder(vcsProvider).ApiEndpoint(apiEndpoint).Token(token).Build()
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 Bitbuckettoken:="secret-bitbucket-token"// Logger// [Optional]// Supported logger is a logger that implements the Log interface.// More information - https://github.com/jfrog/froggit-go/blob/master/vcsclient/logger.gologger:=log.Default()client,err:=vcsclient.NewClientBuilder(vcsProvider).ApiEndpoint(apiEndpoint).Token(token).Build()
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.0apiEndpoint:="https://bitbucket.example.com"// Bitbucket usernameusername:="bitbucket-user"// Password or Bitbucket "App Password'token:="secret-bitbucket-token"// Logger// [Optional]// Supported logger is a logger that implements the Log interface.// More information - https://github.com/jfrog/froggit-go/blob/master/vcsclient/logger.gologger:=log.Default()client,err:=vcsclient.NewClientBuilder(vcsProvider).ApiEndpoint(apiEndpoint).Username(username).Token(token).Build()
Azure DevOps api version v6 is used.
// The VCS provider. Cannot be changed.vcsProvider:=vcsutils.AzureRepos// API endpoint to Azure Repos. Set the organization.apiEndpoint:="https://dev.azure.com/<organization>"// Personal Access Token to Azure DevOpstoken:="secret-azure-devops-token"// Logger// [Optional]// Supported logger is a logger that implements the Log interface.// More information - https://github.com/jfrog/froggit-go/blob/master/vcsclient/logger.gologger:=log.Default()// Project nameproject:="name-of-the-relevant-project"client,err:=vcsclient.NewClientBuilder(vcsProvider).ApiEndpoint(apiEndpoint).Token(token).Project(project).Build()
// Go contextctx:=context.Background()err:=client.TestConnection(ctx)
// Go contextctx:=context.Background()repositories,err:=client.ListRepositories(ctx)
Returns a map between all accessible Apps and their list of repositories.
Note: Currently supported for GitHub Apps only.
// Go contextctx:=context.Background()// List all repositories accessible by the app (for example, a GitHub App installation)appRepositories,err:=client.ListAppRepositories(ctx)iferr!=nil {// handle error}forowner,repos:=rangeappRepositories {fmt.Printf("Owner: %s\n",owner)for_,repo:=rangerepos {fmt.Printf(" - %s\n",repo) }}
// Go contextctx:=context.Background()// Organization or usernameowner:="jfrog"// VCS repositoryrepository:="jfrog-cli"repositoryBranches,err:=client.ListBranches(ctx,owner,repository)
// Go contextctx:=context.Background()// Organization or usernameowner:="jfrog"// VCS repositoryrepository:="jfrog-cli"// Pull Request IDpullRequestID:=1// List all reviews for pull request 1reviews,err:=client.ListPullRequestReviews(ctx,owner,repository,pullRequestID)
// Go contextctx:=context.Background()// Organization or usernameowner:="jfrog"// VCS repositoryrepository:="jfrog-cli"// Repository branchbranch:="master"// Local path in the file systemlocalPath:="/Users/frogger/code/jfrog-cli"repositoryBranches,err:=client.DownloadRepository(ctx,owner,repository,branch,localPath)
// Go contextctx:=context.Background()// Organization or usernameowner:="jfrog"// The event to watchwebhookEvent:=vcsutils.Push// VCS repositoryrepository:="jfrog-cli"// Optional - Webhooks on branches are supported only on GitLabbranch:=""// The URL to send the payload upon a webhook eventpayloadURL:="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)
// Go contextctx:=context.Background()// Organization or usernameowner:="jfrog"// VCS repositoryrepository:="jfrog-cli"// Optional - Webhooks on branches are supported only on GitLabbranch:=""// The URL to send the payload upon a webhook eventpayloadURL:="https://acme.jfrog.io/integration/api/v1/webhook/event"// A token to validate identity of the webhook, created by CreateWebhook commandtoken:="abc123"// The webhook ID returned by the CreateWebhook API, which created this webhookwebhookID:="123"// The event to watchwebhookEvent:=vcsutils.PrCreatederr:=client.UpdateWebhook(ctx,owner,repository,branch,"https://jfrog.com",token,webhookID,webhookEvent)
// Go contextctx:=context.Background()// Organization or usernameowner:="jfrog"// VCS repositoryrepository:="jfrog-cli"// The webhook ID returned by the CreateWebhook API, which created this webhookwebhookID:="123"err:=client.DeleteWebhook(ctx,owner,repository,webhookID)
// Go contextctx:=context.Background()// One of Pass, Fail, Error, or InProgresscommitStatus:=vcsclient.Pass// Organization or usernameowner:="jfrog"// VCS repositoryrepository:="jfrog-cli"// Branch or commit or tag on GitHub and GitLab, commit on Bitbucketref:="5c05522fecf8d93a11752ff255c99fcb0f0557cd"// Title of the commit statustitle:="Xray scanning"// Description of the commit statusdescription:="Run JFrog Xray scan"// URL leads to the platform to provide more information, such as Xray scanning resultsdetailsURL:="https://acme.jfrog.io/ui/xray-scan-results-url"err:=client.SetCommitStatus(ctx,commitStatus,owner,repository,ref,title,description,detailsURL)
// Go contextctx:=context.Background()// Organization or usernameowner:="jfrog"// VCS repositoryrepository:="jfrog-cli"// Commit tag on GitHub and GitLab, commit on Bitbucketref:="5c05522fecf8d93a11752ff255c99fcb0f0557cd"commitStatuses,err:=client.GetCommitStatus(ctx,owner,repository,ref)
// Go contextctx:=context.Background()// Organization or usernameowner:="jfrog"// VCS repositoryrepository:="jfrog-cli"// Source pull request branchsourceBranch:="dev"// Target pull request branchtargetBranch:="main"// Pull request titletitle:="Pull request title"// Pull request descriptiondescription:="Pull request description"err:=client.CreatePullRequest(ctx,owner,repository,sourceBranch,targetBranch,title,description)
// Go contextctx:=context.Background()// Organization or usernameowner:="jfrog"// VCS repositoryrepository:="jfrog-cli"// Target pull request branch, leave empty for no change.targetBranch:="main"// Pull request titletitle:="Pull request title"// Pull request descriptionbody:="Pull request description"// Pull request IDid:="1"// Pull request statestate:=vcsutils.Openerr:=client.UpdatePullRequest(ctx,owner,repository,title,body,targetBranch,id,state)
// Go contextctx:=context.Background()// Organization or usernameowner:="jfrog"// VCS repositoryrepository:="jfrog-cli"openPullRequests,err:=client.ListOpenPullRequestsWithBody(ctx,owner,repository)
// Go contextctx:=context.Background()// Organization or usernameowner:="jfrog"// VCS repositoryrepository:="jfrog-cli"openPullRequests,err:=client.ListOpenPullRequests(ctx,owner,repository)
// Go contextctx:=context.Background()// Organization or usernameowner:="jfrog"// VCS repositoryrepository:="jfrog-cli"// Pull Request IDpullRequestId:=1openPullRequests,err:=client.GetPullRequestByID(ctx,owner,repository,pullRequestId)
// Go contextctx:=context.Background()// Organization or usernameowner:="jfrog"// VCS repositoryrepository:="jfrog-cli"// Comment contentcontent:="Comment content"// Pull Request IDpullRequestID:=5err:=client.AddPullRequestComment(ctx,owner,repository,content,pullRequestID)
// Go contextctx:=context.Background()// Organization or usernameowner:="jfrog"// VCS repositoryrepository:="jfrog-cli"// Pull Request IDpullRequestID:=5// Pull Request Commentcomments:= []PullRequestComment{ {CommentInfo:CommentInfo{Content:"content", },PullRequestDiff:PullRequestDiff{OriginalFilePath: index.jsOriginalStartLine:1OriginalEndLine:1OriginalStartColumn:1OriginalEndColumn:1NewFilePath: index.jsNewStartLine:1NewEndLine:1NewStartColumn:1NewEndColumn:1 }, }}err:=client.AddPullRequestReviewComments(ctx,owner,repository,pullRequestID,comments...)
// Go contextctx:=context.Background()// Organization or usernameowner:="jfrog"// VCS repositoryrepository:="jfrog-cli"// Pull Request IDpullRequestID:=5pullRequestComments,err:=client.ListPullRequestComment(ctx,owner,repository,pullRequestID)
// Go contextctx:=context.Background()// Organization or usernameowner:="jfrog"// VCS repositoryrepository:="jfrog-cli"// Pull Request IDpullRequestID:=5pullRequestComments,err:=client.ListPullRequestReviewComments(ctx,owner,repository,pullRequestID)
// Go contextctx:=context.Background()// Organization or usernameowner:="jfrog"// VCS repositoryrepository:="jfrog-cli"// Pull Request IDpullRequestID:=5// Comment IDcommentID:=17err:=client.DeletePullRequestComment(ctx,owner,repository,pullRequestID,commentID)
// Go contextctx:=context.Background()// Organization or usernameowner:="jfrog"// VCS repositoryrepository:="jfrog-cli"// Pull Request IDpullRequestID:=5// Comment IDcomments:= []CommentInfo{ {ID:2// For GitLabThreadID:7 }}err:=client.DeletePullRequestComment(ctx,owner,repository,pullRequestID,comments...)
// Go contextctx:=context.Background()// Organization or usernameowner:="jfrog"// VCS repositoryrepository:="jfrog-cli"// VCS branchbranch:="dev"// Commits information of the latest branch commitscommitInfo,err:=client.GetCommits(ctx,owner,repository,branch)
// Go contextctx:=context.Background()// Organization or usernameowner:="jfrog"// VCS repositoryrepository:="jfrog-cli"// Commits query optionsoptions:=GitCommitsQueryOptions{Since:time.Date(2021,1,1,0,0,0,0,time.UTC),Until:time.Now(),ListOptions:ListOptions{Page:1,PerPage:30, }, }result,err:=client.GetCommitsWithQueryOptions(ctx,owner,repository,options)
// Go contextctx:=context.Background()// Organization or usernameowner:="jfrog"// VCS repositoryrepository:="jfrog-cli"// VCS branchbranch:="dev"// Commit information of the latest commitcommitInfo,err:=client.GetLatestCommit(ctx,owner,repository,branch)
// Go contextctx:=context.Background()// Organization or usernameowner:="jfrog"// VCS repositoryrepository:="jfrog-cli"// SHA-1 hash of the commitsha:="abcdef0123abcdef4567abcdef8987abcdef6543"// Commit information of requested commitcommitInfo,err:=client.GetCommitBySha(ctx,owner,repository,sha)
// Go contextctx:=context.Background()// Organization or usernameowner:="jfrog"// VCS repositoryrepository:="jfrog-cli"// Commit SHAcommitSHA:="abcdef0123abcdef4567abcdef8987abcdef6543"// List pull requests associated with a specific commitpullRequests,err:=client.ListPullRequestsAssociatedWithCommit(ctx,owner,repository,commitSHA)
TherefBefore...refAfter syntax is used.More about it can be found atCommit Ranges Gitdocumentation.
// Go contextctx:=context.Background()// Organization or usernameowner:="jfrog"// VCS repositoryrepository:="jfrog-cli"// SHA-1 hash of the commit or tag or a branch namerefBefore:="abcdef0123abcdef4567abcdef8987abcdef6543"// SHA-1 hash of the commit or tag or a branch namerefAfter:="main"filePaths,err:=client.GetModifiedFiles(ctx,owner,repository,refBefore,refAfter)
// Go contextctx:=context.Background()// Organization or usernameowner:="jfrog"// VCS repositoryrepository:="jfrog-cli"// An identifier for the keykeyName:="my ssh key"// The public SSH keypublicKey:="ssh-rsa AAAA..."// Access permission of the key: vcsclient.Read or vcsclient.ReadWritepermission=vcsclient.Read// Add a public SSH key to a repositoryerr:=client.AddSshKeyToRepository(ctx,owner,repository,keyName,publicKey,permission)
// Go contextctx:=context.Background()// Organization or usernameowner:="jfrog"// VCS repositoryrepository:="jfrog-cli"// Get information about repositoryrepoInfo,err:=client.GetRepositoryInfo(ctx,owner,repository)
Notice - Get Repository Environment Info is currently supported on GitHub only.
// Go contextctx:=context.Background()// Organization or usernameowner:="jfrog"// VCS repositoryrepository:="jfrog-cli"// Environment namename:="frogbot"// Get information about repository environmentrepoEnvInfo,err:=client.GetRepositoryEnvironmentInfo(ctx,owner,repository,name)
Notice - Labels are not supported in Bitbucket
// Go contextctx:=context.Background()// Organization or usernameowner:="jfrog"// VCS repositoryrepository:="jfrog-cli"// Label infolabelInfo:=LabelInfo{Name:"label-name",Description:"label description",Color:"4AB548",}// Create a labelerr:=client.CreateLabel(ctx,owner,repository,labelInfo)
Notice - Labels are not supported in Bitbucket
// Go contextctx:=context.Background()// Organization or usernameowner:="jfrog"// VCS repositoryrepository:="jfrog-cli"// Label namelabelName:="label-name"// Get a label named "label-name"labelInfo,err:=client.GetLabel(ctx,owner,repository,labelName)
Notice - Labels are not supported in Bitbucket
// Go contextctx:=context.Background()// Organization or usernameowner:="jfrog"// VCS repositoryrepository:="jfrog-cli"// Pull Request IDpullRequestID:=5// List all labels assigned to pull request 5pullRequestLabels,err:=client.ListPullRequestLabels(ctx,owner,repository,pullRequestID)
Notice - Labels are not supported in Bitbucket
// Go contextctx:=context.Background()// Organization or usernameowner:="jfrog"// VCS repositoryrepository:="jfrog-cli"// Label namename:="label-name"// Pull Request IDpullRequestID:=5// Remove label "label-name" from pull request 5err:=client.UnlabelPullRequest(ctx,owner,repository,name,pullRequestID)
Notice - Code Scanning is currently supported on GitHub only.
// Go contextctx:=context.Background()// The account owner of the git repositoryowner:="user"// The name of the repositoryrepo:="my_repo"// The branch name for which the code scanning is relevantbranch:="my_branch"// A string representing the code scanning resultsscanResults:="results"// Uploads the scanning analysis file to the relevant git providersarifID,err:=client.UploadCodeScanning(ctx,owner,repo,branch,scanResults)
Note - This API is currently not supported for Bitbucket Cloud.
// Go contextctx:=context.Background()// The account owner of the git repositoryowner:="user"// The name of the repositoryrepo:="my_repo"// The branch name for which the code scanning is relevantbranch:="my_branch"// A string representing the file path in the repositorypath:="path"// Downloads a file from a repositorycontent,statusCode,err:=client.DownloadFileFromRepo(ctx,owner,repo,branch,path)
Notice - Create Branch is currently supported on GitHub only.
// Go Contextctx:=context.Background()// Organization or usernameowner:="jfrog"// VSC Repositoryrepository:="jfrog-cli"// Source branch to create a new branch fromsourceBranch:="main"// New branch namenewBranch:="my-new-branch"// Create a new brancherr=client.CreateBranch(ctx,owner,repository,sourceBranch,newBranch)
Notice - Allow Workflows is currently supported on GitHub only.
// Go contextctx:=context.Background()// Organizationowner:="jfrog"// Allow workflows for the organizationerr=client.AllowWorkflows(ctx,owner)
Notice - Add Organization Secrets currently supported on GitHub only.
// Go contextctx:=context.Background()// Organizationowner:="jfrog"// Secret namesecret:="key"// Secret value, will be encrypted by froggitsecretValue:="some-secret-value"// Add a secret to the organizationerr=client.AddOrganizationSecret(ctx,owner,secret,secretValue)
Notice - Create Organization Variable is currently supported on GitHub only.
// Go contextctx:=context.Background()// Organizationowner:="jfrog"// Variable namevariableName:="JF_URL"// Variable valuevariableValue:="https://acme.jfrog.io/"// Add a variable to the organizationerr=client.CreateOrgVar(ctx,owner,variableName,variableValue)####GetRepoCollaboratorsNotice-GetRepoCollaboratorsiscurrentlysupportedonGitHubonly.```go// Go contextctx:=context.Background()// Organizationowner:="jfrog"// Repository namerepo:="jfrog-cli"// Affiliation type, can be one of the following: all, direct, outside, memberaffiliation:="direct"// Permission type, can be one of the following: read, write, admin, maintain, triagepermission:="maintain"// Get the list of collaborators for a specific repositorycollaborators,err:=client.GetRepoCollaborators(ctx,owner,repo,affiliation,permission)
Notice - Get Repo Teams By Permissions currently supported on GitHub only.
// Go contextctx:=context.Background()// Organizationowner:="jfrog"// Repository namerepo:="jfrog-cli"// Permission type, can be one of the following: read, write, admin, maintain, triagepermissions:= []string{"maintain","admin"}// Get the list of teams with specific permissions for a repositoryteams,err:=client.GetRepoTeamsByPermissions(ctx,owner,repo,permissions)
Notice - Create Or Update Environment is currently supported on GitHub only.
// Go contextctx:=context.Background()// Organizationowner:="jfrog-org"// Repository namerepo:="big-npm"// Repository environment nameenvName:="frogbot"// List of teams ids to add to the environmentteams:= []int64{12345678}// List of user names to add to the environmentusers:= []string{"eyalk007"}// Create or update the environmenterr=client.CreateOrUpdateEnvironment(ctx,owner,repo,envName,teams,users)
Notice - Commit And Push Files is currently supported on GitHub only.
// Go contextctx:=context.Background()// Organizationowner:="jfrog"// Repository namerepo:="jfrog-cli"// Source branch namesourceBranch:="feature-branch"// Commit messagecommitMessage:="example commit message"// Author nameauthor:="example"//Files To commitfilesToCommit:= []vcsclient.FileToCommit{{Path:".github/workflows/example.yml",Content:"hello world",}}//Author emailauthorEmail:="example@gmail.com"// Commit and push files to the repository in the source brancherr=client.CommitAndPushFiles(ctx,owner,repo,sourceBranch,commitMessage,author,authorEmail,filesToCommit)
Notice - Merge Pull Request is currently supported on GitHub only.
// Go contextctx:=context.Background()// Organizationowner:="jfrog"// Repository namerepo:="jfrog-cli"// pull request numberprNumber:=134// Commit message, empty will use the default commit messagecommitMessage:="example commit message"// Merge the pull requesterr=client.MergePullRequest(ctx,owner,repo,prNumber,commitMessage)
Notice - Create Pull Request Detailed is currently supported on GitHub only.
// Go contextctx:=context.Background()// Organization or usernameowner:="jfrog"// VCS repositoryrepository:="jfrog-cli"// Source pull request branchsourceBranch:="dev"// Target pull request branchtargetBranch:="main"// Pull request titletitle:="Pull request title"// Pull request descriptiondescription:="Pull request description"// Creates a pull request and returns its number and URL.prInfo,err:=client.CreatePullRequestDetailed(ctx,owner,repository,sourceBranch,targetBranch,title,description)
Notice - Upload Snapshot To Dependency Graph is currently supported on GitHub only.
// Go contextctx:=context.Background()// Organization or usernameowner:="jfrog"// VCS repositoryrepository:="jfrog-cli"// SBOM snapshot containing dependency informationsnapshot:=&vcsclient.SbomSnapshot{Version:0,Sha:"5c05522fecf8d93a11752ff255c99fcb0f0557cd",Ref:"refs/heads/main",Job:&vcsclient.JobInfo{Correlator:"job-correlator",ID:"job-id", },Detector:&vcsclient.DetectorInfo{Name:"detector-name",Version:"1.0.0",Url:"https://example.com/detector", },Scanned:time.Now(),Manifests:map[string]*vcsclient.Manifest{"package.json": {Name:"package.json",File:&vcsclient.FileInfo{SourceLocation:"package.json", },Resolved:map[string]*vcsclient.ResolvedDependency{"lodash": {PackageURL:"pkg:npm/lodash@4.17.21",Dependencies: []string{}, }, }, }, },}// Uploads the SBOM snapshot to the GitHub dependency graph taberr:=client.UploadSnapshotToDependencyGraph(ctx,owner,repository,snapshot)
// Go contextctx:=context.Background()// Loggerlogger:= vcsclient.EmptyLogger{}// Webhook contextual informationorigin:= webhookparser.WebhookOrigin{// The VCS provider (required)VcsProvider:vcsutils.GitHub,// Optional URL of the VCS provider (used for building some URLs)OriginURL:"https://api.github.com",// Token to authenticate incoming webhooks. If empty, signature will not be verified.// The token is a random key generated in the CreateWebhook command.Token: []byte("abc123"),}// The HTTP request of the incoming webhookrequest:= http.Request{}webhookInfo,err:=webhookparser.ParseIncomingWebhook(ctx,logger,origin,request)
About
Froggit-Go is a universal Go library, allowing to perform actions on VCS providers.
Topics
Resources
License
Security policy
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Uh oh!
There was an error while loading.Please reload this page.
