Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitae5f1b0

Browse files
authored
add CreateOrgVariable method (#158)
* Add CreateOrgVar method to vsc* Add CreateOrgVar to the documentation
1 parenta1d2b0c commitae5f1b0

File tree

10 files changed

+74
-2
lines changed

10 files changed

+74
-2
lines changed

‎README.md‎

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -900,14 +900,31 @@ ctx := context.Background()
900900
// Organization
901901
owner:="jfrog"
902902
// Secret name
903-
secret:="JF_URL"
903+
secret:="key"
904904
// Secret value, will be encrypted by froggit
905-
secretValue:="https://acme.jfrog.io/"
905+
secretValue:="some-secret-value"
906906

907907
// Add a secret to the organization
908908
err = client.AddOrganizationSecret(ctx, owner, secret, secretValue)
909909
```
910910

911+
####Create Organization Variable
912+
913+
Notice - Create Organization Variable is currently supported on GitHub only.
914+
915+
```go
916+
// Go context
917+
ctx:= context.Background()
918+
// Organization
919+
owner:="jfrog"
920+
// Variable name
921+
variableName:="JF_URL"
922+
// Variable value
923+
variableValue:="https://acme.jfrog.io/"
924+
925+
// Add a variable to the organization
926+
err = client.CreateOrgVar(ctx, owner, variableName, variableValue)
927+
911928
####GetRepoCollaborators
912929

913930
Notice -GetRepoCollaborators is currently supported onGitHub only.

‎vcsclient/azurerepos.go‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -756,6 +756,10 @@ func (client *AzureReposClient) AddOrganizationSecret(ctx context.Context, owner
756756
returngetUnsupportedInAzureError("add organization secret")
757757
}
758758

759+
func (client*AzureReposClient)CreateOrgVariable(ctx context.Context,owner,variableName,variableValuestring)error {
760+
returngetUnsupportedInAzureError("create organization variable")
761+
}
762+
759763
func (client*AzureReposClient)CommitAndPushFiles(ctx context.Context,owner,repo,sourceBranch,commitMessage,authorName,authorEmailstring,files []FileToCommit)error {
760764
returngetUnsupportedInAzureError("commit and push files")
761765
}

‎vcsclient/bitbucketcloud.go‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,10 @@ func (client *BitbucketCloudClient) AddOrganizationSecret(ctx context.Context, o
715715
returnerrBitbucketAddOrganizationSecretNotSupported
716716
}
717717

718+
func (client*BitbucketCloudClient)CreateOrgVariable(ctx context.Context,owner,variableName,variableValuestring)error {
719+
returnerrBitbucketCreateOrgVariableNotSupported
720+
}
721+
718722
func (client*BitbucketCloudClient)CommitAndPushFiles(ctx context.Context,owner,repo,sourceBranch,commitMessage,authorName,authorEmailstring,files []FileToCommit)error {
719723
returnerrBitbucketCommitAndPushFilesNotSupported
720724
}

‎vcsclient/bitbucketcommon.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ var (
2727
errBitbucketCreateBranchNotSupported=fmt.Errorf("creating a branch is %s",notSupportedOnBitbucket)
2828
errBitbucketAllowWorkflowsNotSupported=fmt.Errorf("allow workflows is %s",notSupportedOnBitbucket)
2929
errBitbucketAddOrganizationSecretNotSupported=fmt.Errorf("adding organization secret is %s",notSupportedOnBitbucket)
30+
errBitbucketCreateOrgVariableNotSupported=fmt.Errorf("creating organization variable is %s",notSupportedOnBitbucket)
3031
errBitbucketCommitAndPushFilesNotSupported=fmt.Errorf("commit and push files is %s",notSupportedOnBitbucket)
3132
errBitbucketGetRepoCollaboratorsNotSupported=fmt.Errorf("get repository collaborators is %s",notSupportedOnBitbucket)
3233
errBitbucketGetRepoTeamsByPermissionsNotSupported=fmt.Errorf("get repo teams by permissions is %s",notSupportedOnBitbucket)

‎vcsclient/bitbucketserver.go‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -907,6 +907,10 @@ func (client *BitbucketServerClient) AddOrganizationSecret(ctx context.Context,
907907
returnerrBitbucketAddOrganizationSecretNotSupported
908908
}
909909

910+
func (client*BitbucketServerClient)CreateOrgVariable(ctx context.Context,owner,variableName,variableValuestring)error {
911+
returnerrBitbucketCreateOrgVariableNotSupported
912+
}
913+
910914
func (client*BitbucketServerClient)CommitAndPushFiles(ctx context.Context,owner,repo,sourceBranch,commitMessage,authorName,authorEmailstring,files []FileToCommit)error {
911915
returnerrBitbucketCommitAndPushFilesNotSupported
912916
}

‎vcsclient/github.go‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,6 +1135,25 @@ func (client *GitHubClient) AddOrganizationSecret(ctx context.Context, owner, se
11351135
returnerr
11361136
}
11371137

1138+
func (client*GitHubClient)CreateOrgVariable(ctx context.Context,owner,variableName,variableValuestring)error {
1139+
err:=validateParametersNotBlank(map[string]string{"owner":owner,"variableName":variableName,"variableValue":variableValue})
1140+
iferr!=nil {
1141+
returnerr
1142+
}
1143+
1144+
variable:=&github.ActionsVariable{
1145+
Name:variableName,
1146+
Value:variableValue,
1147+
Visibility:github.String("all"),
1148+
}
1149+
1150+
err=client.runWithRateLimitRetries(func() (*github.Response,error) {
1151+
_,err=client.ghClient.Actions.CreateOrgVariable(ctx,owner,variable)
1152+
returnnil,err
1153+
})
1154+
returnerr
1155+
}
1156+
11381157
func (client*GitHubClient)AllowWorkflows(ctx context.Context,ownerstring)error {
11391158
err:=validateParametersNotBlank(map[string]string{"owner":owner})
11401159
iferr!=nil {

‎vcsclient/github_test.go‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,6 +1074,21 @@ func TestGitHubClient_AddOrganizationSecret(t *testing.T) {
10741074
assert.Error(t,err)
10751075
}
10761076

1077+
funcTestGitHubClient_CreateOrgVariable(t*testing.T) {
1078+
ctx:=context.Background()
1079+
client,cleanUp:=createServerAndClient(t,vcsutils.GitHub,false, github.ActionsVariable{},
1080+
"/orgs/jfrog/actions/variables",createGitHubHandler)
1081+
defercleanUp()
1082+
1083+
// Test with default visibility "all"
1084+
err:=client.CreateOrgVariable(ctx,owner,"JF_URL","test.jfrogdev.org")
1085+
assert.NoError(t,err)
1086+
1087+
// Test with bad client
1088+
err=createBadGitHubClient(t).CreateOrgVariable(ctx,owner,"JF_URL","test.jfrogdev.org")
1089+
assert.Error(t,err)
1090+
}
1091+
10771092
funcTestGitHubClient_CommitAndPushFiles(t*testing.T) {
10781093
ctx:=context.Background()
10791094
sourceBranch:="feature-branch"

‎vcsclient/gitlab.go‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,10 @@ func (client *GitLabClient) AddOrganizationSecret(ctx context.Context, owner, se
795795
returnerrGitLLabAddOrganizationSecretNotSupported
796796
}
797797

798+
func (client*GitLabClient)CreateOrgVariable(ctx context.Context,owner,variableName,variableValuestring)error {
799+
returnerrGitLabCreateOrgVariableNotSupported
800+
}
801+
798802
func (client*GitLabClient)CommitAndPushFiles(ctx context.Context,owner,repo,sourceBranch,commitMessage,authorName,authorEmailstring,files []FileToCommit)error {
799803
returnerrGitLabCommitAndPushFilesNotSupported
800804
}

‎vcsclient/gitlabcommon.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ var errGitLabGetRepoEnvironmentInfoNotSupported = errors.New("get repository env
99
varerrGitLabCreateBranchNotSupported=errors.New("creating a branch is not supported on Gitlab")
1010
varerrGitLabAllowWorkflowsNotSupported=errors.New("allow workflows is not supported on Gitlab")
1111
varerrGitLLabAddOrganizationSecretNotSupported=errors.New("adding organization secret is not supported on Gitlab")
12+
varerrGitLabCreateOrgVariableNotSupported=errors.New("creating organization variable is not supported on Gitlab")
1213
varerrGitLabCommitAndPushFilesNotSupported=errors.New("commit and push files is not supported on Gitlab")
1314
varerrGitLabGetCollaboratorsNotSupported=errors.New("get collaborators is not supported on Gitlab")
1415
varerrGitLabGetRepoTeamsByPermissionsNotSupported=errors.New("get repository Teams By permissions is not supported on Gitlab")

‎vcsclient/vcsclient.go‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,9 @@ type VcsClient interface {
376376
// AddOrganizationSecret adds a secret to the organization
377377
AddOrganizationSecret(ctx context.Context,owner,secretName,secretValuestring)error
378378

379+
// CreateOrgVariable creates a variable in the organization
380+
CreateOrgVariable(ctx context.Context,owner,variableName,variableValuestring)error
381+
379382
// CommitAndPushFiles commits and pushes files to the specified branch in the repository
380383
CommitAndPushFiles(ctx context.Context,owner,repo,sourceBranch,commitMessage,authorName,authorEmailstring,files []FileToCommit)error
381384

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp