Project status
VCS Clients
Create Clients
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)
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)
Get Commit Status
// Go context
ctx := context.Background()
// Organization or username
owner := "jfrog"
// VCS repository
repository := "jfrog-cli"
// Commit tag on GitHub and GitLab, commit on Bitbucket
ref := "5c05522fecf8d93a11752ff255c99fcb0f0557cd"
commitStatuses, err := client.GetCommitStatus(ctx, owner, repository, ref)
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)
Update Pull Request
// Go context
ctx := context.Background()
// Organization or username
owner := "jfrog"
// VCS repository
repository := "jfrog-cli"
// Target pull request branch, leave empty for no change.
targetBranch := "main"
// Pull request title
title := "Pull request title"
// Pull request description
body := "Pull request description"
// Pull request ID
id := "1"
// Pull request state
state := vcsutils.Open
err := client.UpdatePullRequest(ctx, owner, repository, title, body, targetBranch, id, state)
List Open Pull Requests With Body
// Go context
ctx := context.Background()
// Organization or username
owner := "jfrog"
// VCS repository
repository := "jfrog-cli"
openPullRequests, err := client.ListOpenPullRequestsWithBody(ctx, owner, repository)
List Open Pull Requests
// Go context
ctx := context.Background()
// Organization or username
owner := "jfrog"
// VCS repository
repository := "jfrog-cli"
openPullRequests, err := client.ListOpenPullRequests(ctx, owner, repository)
Get Pull Request By ID
// Go context
ctx := context.Background()
// Organization or username
owner := "jfrog"
// VCS repository
repository := "jfrog-cli"
// Pull Request ID
pullRequestId := 1
openPullRequests, err := client.GetPullRequestByID(ctx, owner, repository, pullRequestId)
Add Pull Request Comment
// Go context
ctx := context.Background()
// Organization or username
owner := "jfrog"
// VCS repository
repository := "jfrog-cli"
// Comment content
content := "Comment content"
// Pull Request ID
pullRequestID := 5
err := client.AddPullRequestComment(ctx, owner, repository, content, pullRequestID)
Add Pull Request Review Comments
// Go context
ctx := context.Background()
// Organization or username
owner := "jfrog"
// VCS repository
repository := "jfrog-cli"
// Pull Request ID
pullRequestID := 5
// Pull Request Comment
comments := []PullRequestComment{
{
CommentInfo: CommentInfo{
Content: "content",
},
PullRequestDiff: PullRequestDiff{
OriginalFilePath: index.js
OriginalStartLine: 1
OriginalEndLine: 1
OriginalStartColumn: 1
OriginalEndColumn: 1
NewFilePath: index.js
NewStartLine: 1
NewEndLine: 1
NewStartColumn: 1
NewEndColumn: 1
},
}
}
err := client.AddPullRequestReviewComments(ctx, owner, repository, pullRequestID, comments...)
List Pull Request Comments
// Go context
ctx := context.Background()
// Organization or username
owner := "jfrog"
// VCS repository
repository := "jfrog-cli"
// Pull Request ID
pullRequestID := 5
pullRequestComments, err := client.ListPullRequestComment(ctx, owner, repository, pullRequestID)
List Pull Request Review Comments
// Go context
ctx := context.Background()
// Organization or username
owner := "jfrog"
// VCS repository
repository := "jfrog-cli"
// Pull Request ID
pullRequestID := 5
pullRequestComments, err := client.ListPullRequestReviewComments(ctx, owner, repository, pullRequestID)
Delete Pull Request Comment
// Go context
ctx := context.Background()
// Organization or username
owner := "jfrog"
// VCS repository
repository := "jfrog-cli"
// Pull Request ID
pullRequestID := 5
// Comment ID
commentID := 17
err := client.DeletePullRequestComment(ctx, owner, repository, pullRequestID, commentID)
Delete Pull Request Review Comments
// Go context
ctx := context.Background()
// Organization or username
owner := "jfrog"
// VCS repository
repository := "jfrog-cli"
// Pull Request ID
pullRequestID := 5
// Comment ID
comments := []CommentInfo{
{
ID: 2
// For GitLab
ThreadID: 7
}
}
err := client.DeletePullRequestComment(ctx, owner, repository, pullRequestID, comments...)
Get Commits
// Go context
ctx := context.Background()
// Organization or username
owner := "jfrog"
// VCS repository
repository := "jfrog-cli"
// VCS branch
branch := "dev"
// Commits information of the latest branch commits
commitInfo, err := client.GetCommits(ctx, owner, repository, branch)
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)
Get List of Modified Files
The refBefore...refAfter
syntax is used.
More about it can be found at Commit Ranges Git
documentation.
// Go context
ctx := context.Background()
// Organization or username
owner := "jfrog"
// VCS repository
repository := "jfrog-cli"
// SHA-1 hash of the commit or tag or a branch name
refBefore := "abcdef0123abcdef4567abcdef8987abcdef6543"
// SHA-1 hash of the commit or tag or a branch name
refAfter := "main"
filePaths, err := client.GetModifiedFiles(ctx, owner, repository, refBefore, refAfter)
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()
// Logger
logger := vcsclient.EmptyLogger{}
// Webhook contextual information
origin := 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 webhook
request := http.Request{}
webhookInfo, err := webhookparser.ParseIncomingWebhook(ctx, logger, origin, request)