Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
go-gitlab
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
go-gitlab
Commits
5dabb35f
Commit
5dabb35f
authored
Jun 25, 2019
by
Marcin Tojek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add support for revert a commit
parent
9809d8e1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
114 additions
and
0 deletions
+114
-0
commits.go
commits.go
+31
-0
commits_test.go
commits_test.go
+83
-0
No files found.
commits.go
View file @
5dabb35f
...
...
@@ -515,3 +515,34 @@ func (s *CommitsService) CherryPickCommit(pid interface{}, sha string, opt *Cher
return
c
,
resp
,
err
}
// RevertCommitOptions represents the available RevertCommit() options.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/commits.html#revert-a-commit
type
RevertCommitOptions
struct
{
Branch
*
string
`url:"branch,omitempty" json:"branch,omitempty"`
}
// RevertCommit reverts a commit in a given branch.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/commits.html#revert-a-commit
func
(
s
*
CommitsService
)
RevertCommit
(
pid
interface
{},
sha
string
,
opt
*
RevertCommitOptions
,
options
...
OptionFunc
)
(
*
Commit
,
*
Response
,
error
)
{
project
,
err
:=
parseID
(
pid
)
if
err
!=
nil
{
return
nil
,
nil
,
err
}
u
:=
fmt
.
Sprintf
(
"projects/%s/repository/commits/%s/revert"
,
pathEscape
(
project
),
sha
)
req
,
err
:=
s
.
client
.
NewRequest
(
"POST"
,
u
,
opt
,
options
)
if
err
!=
nil
{
return
nil
,
nil
,
err
}
var
c
*
Commit
resp
,
err
:=
s
.
client
.
Do
(
req
,
&
c
)
if
err
!=
nil
{
return
nil
,
resp
,
err
}
return
c
,
resp
,
err
}
commits_test.go
View file @
5dabb35f
...
...
@@ -9,6 +9,8 @@ import (
"github.com/stretchr/testify/assert"
)
var
testRevertCommitTargetBranch
=
"release"
func
TestGetCommit
(
t
*
testing
.
T
)
{
mux
,
server
,
client
:=
setup
()
defer
teardown
(
server
)
...
...
@@ -91,3 +93,84 @@ func TestSetCommitStatus(t *testing.T) {
t
.
Errorf
(
"Commits.SetCommitStatus returned %+v, want %+v"
,
status
,
want
)
}
}
func
TestRevertCommit_NoOptions
(
t
*
testing
.
T
)
{
mux
,
server
,
client
:=
setup
()
defer
teardown
(
server
)
mux
.
HandleFunc
(
"/api/v4/projects/1/repository/commits/b0b3a907f41409829b307a28b82fdbd552ee5a27/revert"
,
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
testMethod
(
t
,
r
,
"POST"
)
mustWriteHTTPResponse
(
t
,
w
,
"testdata/get_commit.json"
)
})
commit
,
resp
,
err
:=
client
.
Commits
.
RevertCommit
(
"1"
,
"b0b3a907f41409829b307a28b82fdbd552ee5a27"
,
nil
)
if
err
!=
nil
{
t
.
Fatalf
(
"Commits.RevertCommit returned error: %v, response: %v"
,
err
,
resp
)
}
want
:=
&
Commit
{
ID
:
"6104942438c14ec7bd21c6cd5bd995272b3faff6"
,
ShortID
:
"6104942438c"
,
Title
:
"Sanitize for network graph"
,
AuthorName
:
"randx"
,
AuthorEmail
:
"dmitriy.zaporozhets@gmail.com"
,
CommitterName
:
"Dmitriy"
,
CommitterEmail
:
"dmitriy.zaporozhets@gmail.com"
,
Message
:
"Sanitize for network graph"
,
ParentIDs
:
[]
string
{
"ae1d9fb46aa2b07ee9836d49862ec4e2c46fbbba"
},
Stats
:
&
CommitStats
{
Additions
:
15
,
Deletions
:
10
,
Total
:
25
},
Status
:
BuildState
(
Running
),
LastPipeline
:
&
PipelineInfo
{
ID
:
8
,
Ref
:
"master"
,
SHA
:
"2dc6aa325a317eda67812f05600bdf0fcdc70ab0"
,
Status
:
"created"
,
WebURL
:
"https://gitlab.com/gitlab-org/gitlab-ce/pipelines/54268416"
,
},
ProjectID
:
13083
,
}
assert
.
Equal
(
t
,
want
,
commit
)
}
func
TestRevertCommit_WithOptions
(
t
*
testing
.
T
)
{
mux
,
server
,
client
:=
setup
()
defer
teardown
(
server
)
mux
.
HandleFunc
(
"/api/v4/projects/1/repository/commits/b0b3a907f41409829b307a28b82fdbd552ee5a27/revert"
,
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
testMethod
(
t
,
r
,
"POST"
)
testBody
(
t
,
r
,
`{"branch":"release"}`
)
mustWriteHTTPResponse
(
t
,
w
,
"testdata/get_commit.json"
)
})
commit
,
resp
,
err
:=
client
.
Commits
.
RevertCommit
(
"1"
,
"b0b3a907f41409829b307a28b82fdbd552ee5a27"
,
&
RevertCommitOptions
{
Branch
:
&
testRevertCommitTargetBranch
,
})
if
err
!=
nil
{
t
.
Fatalf
(
"Commits.RevertCommit returned error: %v, response: %v"
,
err
,
resp
)
}
want
:=
&
Commit
{
ID
:
"6104942438c14ec7bd21c6cd5bd995272b3faff6"
,
ShortID
:
"6104942438c"
,
Title
:
"Sanitize for network graph"
,
AuthorName
:
"randx"
,
AuthorEmail
:
"dmitriy.zaporozhets@gmail.com"
,
CommitterName
:
"Dmitriy"
,
CommitterEmail
:
"dmitriy.zaporozhets@gmail.com"
,
Message
:
"Sanitize for network graph"
,
ParentIDs
:
[]
string
{
"ae1d9fb46aa2b07ee9836d49862ec4e2c46fbbba"
},
Stats
:
&
CommitStats
{
Additions
:
15
,
Deletions
:
10
,
Total
:
25
},
Status
:
BuildState
(
Running
),
LastPipeline
:
&
PipelineInfo
{
ID
:
8
,
Ref
:
"master"
,
SHA
:
"2dc6aa325a317eda67812f05600bdf0fcdc70ab0"
,
Status
:
"created"
,
WebURL
:
"https://gitlab.com/gitlab-org/gitlab-ce/pipelines/54268416"
,
},
ProjectID
:
13083
,
}
assert
.
Equal
(
t
,
want
,
commit
)
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment