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
92690cdf
Unverified
Commit
92690cdf
authored
May 19, 2019
by
Sander van Harmelen
Committed by
GitHub
May 19, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #625 from pcarranza/pc/add-fork-project-options
Add Fork Project Options
parents
ddb4d033
f0166434
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
2 deletions
+40
-2
projects.go
projects.go
+11
-2
projects_test.go
projects_test.go
+29
-0
No files found.
projects.go
View file @
92690cdf
...
...
@@ -557,18 +557,27 @@ func (s *ProjectsService) EditProject(pid interface{}, opt *EditProjectOptions,
return
p
,
resp
,
err
}
// ForkProjectOptions represents the available ForkProject() options.
//
// GitLab API docs: https://docs.gitlab.com/ce/api/projects.html#fork-project
type
ForkProjectOptions
struct
{
Namespace
*
string
`url:"namespace,omitempty" json:"namespace,omitempty"`
Name
*
string
`url:"name,omitempty" json:"name,omitempty" `
Path
*
string
`url:"path,omitempty" json:"path,omitempty"`
}
// ForkProject forks a project into the user namespace of the authenticated
// user.
//
// GitLab API docs: https://docs.gitlab.com/ce/api/projects.html#fork-project
func
(
s
*
ProjectsService
)
ForkProject
(
pid
interface
{},
options
...
OptionFunc
)
(
*
Project
,
*
Response
,
error
)
{
func
(
s
*
ProjectsService
)
ForkProject
(
pid
interface
{},
opt
*
ForkProjectOptions
,
opt
ions
...
OptionFunc
)
(
*
Project
,
*
Response
,
error
)
{
project
,
err
:=
parseID
(
pid
)
if
err
!=
nil
{
return
nil
,
nil
,
err
}
u
:=
fmt
.
Sprintf
(
"projects/%s/fork"
,
pathEscape
(
project
))
req
,
err
:=
s
.
client
.
NewRequest
(
"POST"
,
u
,
nil
,
options
)
req
,
err
:=
s
.
client
.
NewRequest
(
"POST"
,
u
,
opt
,
options
)
if
err
!=
nil
{
return
nil
,
nil
,
err
}
...
...
projects_test.go
View file @
92690cdf
...
...
@@ -522,3 +522,32 @@ func TestChangeAllowedApprovers(t *testing.T) {
t
.
Errorf
(
"Projects.ChangeAllowedApprovers returned %+v, want %+v"
,
approvals
,
want
)
}
}
func
TestForkProject
(
t
*
testing
.
T
)
{
mux
,
server
,
client
:=
setup
()
defer
teardown
(
server
)
namespace
:=
"mynamespace"
name
:=
"myreponame"
path
:=
"myrepopath"
mux
.
HandleFunc
(
"/api/v4/projects/1/fork"
,
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
testMethod
(
t
,
r
,
"POST"
)
testBody
(
t
,
r
,
fmt
.
Sprintf
(
`{"namespace":"%s","name":"%s","path":"%s"}`
,
namespace
,
name
,
path
))
fmt
.
Fprint
(
w
,
`{"id":2}`
)
})
project
,
_
,
err
:=
client
.
Projects
.
ForkProject
(
1
,
&
ForkProjectOptions
{
Namespace
:
&
namespace
,
Name
:
&
name
,
Path
:
&
path
,
})
if
err
!=
nil
{
t
.
Errorf
(
"Projects.ForkProject returned error: %v"
,
err
)
}
want
:=
&
Project
{
ID
:
2
}
if
!
reflect
.
DeepEqual
(
want
,
project
)
{
t
.
Errorf
(
"Projects.ForProject returned %+v, want %+v"
,
project
,
want
)
}
}
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