-
Notifications
You must be signed in to change notification settings - Fork 237
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feat]: [PL-24913]: Add the support for create and update file in bit…
…bucket server (#177) * [PL-24913]: Add the support for create and update api in bitbucket server * [PL-24913]: Add the tests for create and update of file in bitbucket server
- Loading branch information
1 parent
30f8094
commit 78b5e76
Showing
7 changed files
with
237 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package integration | ||
|
||
import ( | ||
"context" | ||
"net/http" | ||
"testing" | ||
|
||
"github.com/drone/go-scm/scm" | ||
"github.com/drone/go-scm/scm/driver/stash" | ||
"github.com/drone/go-scm/scm/transport" | ||
) | ||
|
||
func TestCreateUpdateDeleteFileStash(t *testing.T) { | ||
if token == "" { | ||
t.Skip("Skipping, Acceptance test") | ||
} | ||
client, _ = stash.New(endpoint) | ||
client.Client = &http.Client{ | ||
Transport: &transport.BasicAuth{ | ||
Username: username, | ||
Password: token, | ||
}, | ||
} | ||
// get latest commit first | ||
currentCommit, commitErr := GetCurrentCommitOfBranch(client, "master") | ||
if commitErr != nil { | ||
t.Errorf("we got an error %v", commitErr) | ||
} | ||
// create a new file | ||
createParams := scm.ContentParams{ | ||
Message: "go-scm create crud file", | ||
Data: []byte("hello"), | ||
Branch: "master", | ||
Sha: currentCommit, | ||
} | ||
createResponse, createErr := client.Contents.Create(context.Background(), repoID, "README5", &createParams) | ||
if createErr != nil { | ||
t.Errorf("Contents.Create we got an error %v", createErr) | ||
} | ||
if createResponse.Status != http.StatusOK { | ||
t.Errorf("Contents.Create we did not get a 201 back %v", createResponse.Status) | ||
} | ||
// get latest commit first | ||
currentCommit, commitErr = GetCurrentCommitOfBranch(client, "main") | ||
if commitErr != nil { | ||
t.Errorf("we got an error %v", commitErr) | ||
} | ||
// update the file | ||
updateParams := scm.ContentParams{ | ||
Message: "go-scm update crud file", | ||
Data: []byte("updated test data"), | ||
Branch: "master", | ||
Sha: currentCommit, | ||
} | ||
updateResponse, updateErr := client.Contents.Update(context.Background(), repoID, "README5", &updateParams) | ||
if updateErr != nil { | ||
t.Errorf("Contents.Update we got an error %v", updateErr) | ||
} | ||
if updateResponse.Status != http.StatusOK { | ||
t.Errorf("Contents.Update we did not get a 201 back %v", updateResponse.Status) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,26 @@ | ||
package integration | ||
|
||
import ( | ||
"context" | ||
"os" | ||
|
||
"github.com/drone/go-scm/scm" | ||
) | ||
|
||
var ( | ||
client *scm.Client | ||
token = os.Getenv("BITBUCKET_SERVER_TOKEN") | ||
client *scm.Client | ||
token = os.Getenv("BITBUCKET_SERVER_TOKEN") | ||
|
||
endpoint = "https://bitbucket.dev.harness.io/" | ||
repoID = "har/scm-integration-test-repo" | ||
username = "harnessadmin" | ||
commitId = "f675c4b55841908d7c338c500c8f4cb844fd9be7" | ||
) | ||
|
||
func GetCurrentCommitOfBranch(client *scm.Client, branch string) (string, error) { | ||
commits, _, err := client.Git.ListCommits(context.Background(), repoID, scm.CommitListOptions{Ref: branch}) | ||
if err != nil { | ||
return "", err | ||
} | ||
return commits[0].Sha, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"id": "abcdef0123abcdef4567abcdef8987abcdef6543", | ||
"displayId": "abcdef0123a", | ||
"author": { | ||
"name": "charlie", | ||
"emailAddress": "charlie@example.com" | ||
}, | ||
"authorTimestamp": 1636089306104, | ||
"committer": { | ||
"name": "charlie", | ||
"emailAddress": "charlie@example.com" | ||
}, | ||
"committerTimestamp": 1636089306104, | ||
"message": "WIP on feature 1", | ||
"parents": [ | ||
{ | ||
"id": "abcdef0123abcdef4567abcdef8987abcdef6543", | ||
"displayId": "abcdef0" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"id": "abcdef0123abcdef4567abcdef8987abcdef6543", | ||
"displayId": "abcdef0123a", | ||
"author": { | ||
"name": "charlie", | ||
"emailAddress": "charlie@example.com" | ||
}, | ||
"authorTimestamp": 1636089306104, | ||
"committer": { | ||
"name": "charlie", | ||
"emailAddress": "charlie@example.com" | ||
}, | ||
"committerTimestamp": 1636089306104, | ||
"message": "WIP on feature 1", | ||
"parents": [ | ||
{ | ||
"id": "abcdef0123abcdef4567abcdef8987abcdef6543", | ||
"displayId": "abcdef0" | ||
} | ||
] | ||
} |