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
2bf0bc1c
Commit
2bf0bc1c
authored
Jul 12, 2017
by
Sander van Harmelen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update endpoints for repository files to V4 API (#184)
parent
31369e5a
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
53 additions
and
32 deletions
+53
-32
commits.go
commits.go
+0
-0
pipelines.go
examples/pipelines.go
+1
-1
repository_files.go
examples/repository_files.go
+4
-6
repositories.go
repositories.go
+3
-11
repository_files.go
repository_files.go
+45
-14
No files found.
commits.go
View file @
2bf0bc1c
This diff is collapsed.
Click to expand it.
examples/pipelines.go
View file @
2bf0bc1c
...
...
@@ -16,6 +16,6 @@ func pipelineExample() {
}
for
_
,
pipeline
:=
range
pipelines
{
log
.
Printf
(
"Found pipeline: %
s
"
,
pipeline
)
log
.
Printf
(
"Found pipeline: %
v
"
,
pipeline
)
}
}
examples/repository_files.go
View file @
2bf0bc1c
...
...
@@ -12,26 +12,24 @@ func repositoryFileExample() {
// Create a new repository file
cf
:=
&
gitlab
.
CreateFileOptions
{
FilePath
:
gitlab
.
String
(
"file.go"
),
BranchName
:
gitlab
.
String
(
"master"
),
Branch
:
gitlab
.
String
(
"master"
),
Encoding
:
gitlab
.
String
(
"text"
),
Content
:
gitlab
.
String
(
"My file contents"
),
CommitMessage
:
gitlab
.
String
(
"Adding a test file"
),
}
file
,
_
,
err
:=
git
.
RepositoryFiles
.
CreateFile
(
"myname/myproject"
,
cf
)
file
,
_
,
err
:=
git
.
RepositoryFiles
.
CreateFile
(
"myname/myproject"
,
"file.go"
,
cf
)
if
err
!=
nil
{
log
.
Fatal
(
err
)
}
// Update a repository file
uf
:=
&
gitlab
.
UpdateFileOptions
{
FilePath
:
gitlab
.
String
(
file
.
FilePath
),
BranchName
:
gitlab
.
String
(
"master"
),
Branch
:
gitlab
.
String
(
"master"
),
Encoding
:
gitlab
.
String
(
"text"
),
Content
:
gitlab
.
String
(
"My file content"
),
CommitMessage
:
gitlab
.
String
(
"Fixing typo"
),
}
_
,
_
,
err
=
git
.
RepositoryFiles
.
UpdateFile
(
"myname/myproject"
,
uf
)
_
,
_
,
err
=
git
.
RepositoryFiles
.
UpdateFile
(
"myname/myproject"
,
file
.
FilePath
,
uf
)
if
err
!=
nil
{
log
.
Fatal
(
err
)
}
...
...
repositories.go
View file @
2bf0bc1c
...
...
@@ -80,26 +80,18 @@ func (s *RepositoriesService) ListTree(pid interface{}, opt *ListTreeOptions, op
return
t
,
resp
,
err
}
// RawFileContentOptions represents the available RawFileContent() options.
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/repositories.html#raw-file-content
type
RawFileContentOptions
struct
{
FilePath
*
string
`url:"filepath,omitempty" json:"filepath,omitempty"`
}
// RawFileContent gets the raw file contents for a file by commit SHA and path
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/repositories.html#raw-file-content
func
(
s
*
RepositoriesService
)
RawFileContent
(
pid
interface
{},
sha
string
,
opt
*
RawFileContentOptions
,
opt
ions
...
OptionFunc
)
([]
byte
,
*
Response
,
error
)
{
func
(
s
*
RepositoriesService
)
RawFileContent
(
pid
interface
{},
sha
string
,
options
...
OptionFunc
)
([]
byte
,
*
Response
,
error
)
{
project
,
err
:=
parseID
(
pid
)
if
err
!=
nil
{
return
nil
,
nil
,
err
}
u
:=
fmt
.
Sprintf
(
"projects/%s/repository/blobs/%s"
,
url
.
QueryEscape
(
project
),
sha
)
req
,
err
:=
s
.
client
.
NewRequest
(
"GET"
,
u
,
opt
,
options
)
req
,
err
:=
s
.
client
.
NewRequest
(
"GET"
,
u
,
nil
,
options
)
if
err
!=
nil
{
return
nil
,
nil
,
err
}
...
...
@@ -122,7 +114,7 @@ func (s *RepositoriesService) RawBlobContent(pid interface{}, sha string, option
if
err
!=
nil
{
return
nil
,
nil
,
err
}
u
:=
fmt
.
Sprintf
(
"projects/%s/repository/
raw_blobs/%s
"
,
url
.
QueryEscape
(
project
),
sha
)
u
:=
fmt
.
Sprintf
(
"projects/%s/repository/
blobs/%s/raw
"
,
url
.
QueryEscape
(
project
),
sha
)
req
,
err
:=
s
.
client
.
NewRequest
(
"GET"
,
u
,
nil
,
options
)
if
err
!=
nil
{
...
...
repository_files.go
View file @
2bf0bc1c
...
...
@@ -50,7 +50,7 @@ func (r File) String() string {
// GetFileOptions represents the available GetFile() options.
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/repository_files.html#get-file-from-re
s
pository
// https://docs.gitlab.com/ce/api/repository_files.html#get-file-from-repository
type
GetFileOptions
struct
{
Ref
*
string
`url:"ref,omitempty" json:"ref,omitempty"`
}
...
...
@@ -59,7 +59,7 @@ type GetFileOptions struct {
// name, size, content. Note that file content is Base64 encoded.
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/repository_files.html#get-file-from-re
s
pository
// https://docs.gitlab.com/ce/api/repository_files.html#get-file-from-repository
func
(
s
*
RepositoryFilesService
)
GetFile
(
pid
interface
{},
fileName
string
,
opt
*
GetFileOptions
,
options
...
OptionFunc
)
(
*
File
,
*
Response
,
error
)
{
project
,
err
:=
parseID
(
pid
)
if
err
!=
nil
{
...
...
@@ -81,6 +81,39 @@ func (s *RepositoryFilesService) GetFile(pid interface{}, fileName string, opt *
return
f
,
resp
,
err
}
// GetRawFileOptions represents the available GetRawFile() options.
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/repository_files.html#get-raw-file-from-repository
type
GetRawFileOptions
struct
{
Ref
*
string
`url:"ref,omitempty" json:"ref,omitempty"`
}
// GetRawFile allows you to receive the raw file in repository.
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/repository_files.html#get-raw-file-from-repository
func
(
s
*
RepositoryFilesService
)
GetRawFile
(
pid
interface
{},
fileName
string
,
opt
*
GetRawFileOptions
,
options
...
OptionFunc
)
(
*
File
,
*
Response
,
error
)
{
project
,
err
:=
parseID
(
pid
)
if
err
!=
nil
{
return
nil
,
nil
,
err
}
u
:=
fmt
.
Sprintf
(
"projects/%s/repository/files/%s/raw"
,
url
.
QueryEscape
(
project
),
url
.
QueryEscape
(
fileName
))
req
,
err
:=
s
.
client
.
NewRequest
(
"GET"
,
u
,
opt
,
options
)
if
err
!=
nil
{
return
nil
,
nil
,
err
}
f
:=
new
(
File
)
resp
,
err
:=
s
.
client
.
Do
(
req
,
f
)
if
err
!=
nil
{
return
nil
,
resp
,
err
}
return
f
,
resp
,
err
}
// FileInfo represents file details of a GitLab repository file.
//
// GitLab API docs: https://docs.gitlab.com/ce/api/repository_files.html
...
...
@@ -98,8 +131,7 @@ func (r FileInfo) String() string {
// GitLab API docs:
// https://docs.gitlab.com/ce/api/repository_files.html#create-new-file-in-repository
type
CreateFileOptions
struct
{
FilePath
*
string
`url:"file_path,omitempty" json:"file_path,omitempty"`
BranchName
*
string
`url:"branch_name,omitempty" json:"branch_name,omitempty"`
Branch
*
string
`url:"branch,omitempty" json:"branch,omitempty"`
Encoding
*
string
`url:"encoding,omitempty" json:"encoding,omitempty"`
AuthorEmail
*
string
`url:"author_email,omitempty" json:"author_email,omitempty"`
AuthorName
*
string
`url:"author_name,omitempty" json:"author_name,omitempty"`
...
...
@@ -111,12 +143,12 @@ type CreateFileOptions struct {
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/repository_files.html#create-new-file-in-repository
func
(
s
*
RepositoryFilesService
)
CreateFile
(
pid
interface
{},
opt
*
CreateFileOptions
,
options
...
OptionFunc
)
(
*
FileInfo
,
*
Response
,
error
)
{
func
(
s
*
RepositoryFilesService
)
CreateFile
(
pid
interface
{},
fileName
string
,
opt
*
CreateFileOptions
,
options
...
OptionFunc
)
(
*
FileInfo
,
*
Response
,
error
)
{
project
,
err
:=
parseID
(
pid
)
if
err
!=
nil
{
return
nil
,
nil
,
err
}
u
:=
fmt
.
Sprintf
(
"projects/%s/repository/files
"
,
url
.
QueryEscape
(
project
))
u
:=
fmt
.
Sprintf
(
"projects/%s/repository/files
/%s"
,
url
.
QueryEscape
(
project
),
url
.
QueryEscape
(
fileName
))
req
,
err
:=
s
.
client
.
NewRequest
(
"POST"
,
u
,
opt
,
options
)
if
err
!=
nil
{
...
...
@@ -137,25 +169,25 @@ func (s *RepositoryFilesService) CreateFile(pid interface{}, opt *CreateFileOpti
// GitLab API docs:
// https://docs.gitlab.com/ce/api/repository_files.html#update-existing-file-in-repository
type
UpdateFileOptions
struct
{
FilePath
*
string
`url:"file_path,omitempty" json:"file_path,omitempty"`
BranchName
*
string
`url:"branch_name,omitempty" json:"branch_name,omitempty"`
Branch
*
string
`url:"branch,omitempty" json:"branch,omitempty"`
Encoding
*
string
`url:"encoding,omitempty" json:"encoding,omitempty"`
AuthorEmail
*
string
`url:"author_email,omitempty" json:"author_email,omitempty"`
AuthorName
*
string
`url:"author_name,omitempty" json:"author_name,omitempty"`
Content
*
string
`url:"content,omitempty" json:"content,omitempty"`
CommitMessage
*
string
`url:"commit_message,omitempty" json:"commit_message,omitempty"`
LastCommitID
*
string
`url:"last_commit_id,omitempty" json:"last_commit_id,omitempty"`
}
// UpdateFile updates an existing file in a repository
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/repository_files.html#update-existing-file-in-repository
func
(
s
*
RepositoryFilesService
)
UpdateFile
(
pid
interface
{},
opt
*
UpdateFileOptions
,
options
...
OptionFunc
)
(
*
FileInfo
,
*
Response
,
error
)
{
func
(
s
*
RepositoryFilesService
)
UpdateFile
(
pid
interface
{},
fileName
string
,
opt
*
UpdateFileOptions
,
options
...
OptionFunc
)
(
*
FileInfo
,
*
Response
,
error
)
{
project
,
err
:=
parseID
(
pid
)
if
err
!=
nil
{
return
nil
,
nil
,
err
}
u
:=
fmt
.
Sprintf
(
"projects/%s/repository/files
"
,
url
.
QueryEscape
(
project
))
u
:=
fmt
.
Sprintf
(
"projects/%s/repository/files
/%s"
,
url
.
QueryEscape
(
project
),
url
.
QueryEscape
(
fileName
))
req
,
err
:=
s
.
client
.
NewRequest
(
"PUT"
,
u
,
opt
,
options
)
if
err
!=
nil
{
...
...
@@ -176,8 +208,7 @@ func (s *RepositoryFilesService) UpdateFile(pid interface{}, opt *UpdateFileOpti
// GitLab API docs:
// https://docs.gitlab.com/ce/api/repository_files.html#delete-existing-file-in-repository
type
DeleteFileOptions
struct
{
FilePath
*
string
`url:"file_path,omitempty" json:"file_path,omitempty"`
BranchName
*
string
`url:"branch_name,omitempty" json:"branch_name,omitempty"`
Branch
*
string
`url:"branch,omitempty" json:"branch,omitempty"`
AuthorEmail
*
string
`url:"author_email,omitempty" json:"author_email,omitempty"`
AuthorName
*
string
`url:"author_name,omitempty" json:"author_name,omitempty"`
CommitMessage
*
string
`url:"commit_message,omitempty" json:"commit_message,omitempty"`
...
...
@@ -187,12 +218,12 @@ type DeleteFileOptions struct {
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/repository_files.html#delete-existing-file-in-repository
func
(
s
*
RepositoryFilesService
)
DeleteFile
(
pid
interface
{},
opt
*
DeleteFileOptions
,
options
...
OptionFunc
)
(
*
FileInfo
,
*
Response
,
error
)
{
func
(
s
*
RepositoryFilesService
)
DeleteFile
(
pid
interface
{},
fileName
string
,
opt
*
DeleteFileOptions
,
options
...
OptionFunc
)
(
*
FileInfo
,
*
Response
,
error
)
{
project
,
err
:=
parseID
(
pid
)
if
err
!=
nil
{
return
nil
,
nil
,
err
}
u
:=
fmt
.
Sprintf
(
"projects/%s/repository/files
"
,
url
.
QueryEscape
(
project
))
u
:=
fmt
.
Sprintf
(
"projects/%s/repository/files
/%s"
,
url
.
QueryEscape
(
project
),
url
.
QueryEscape
(
fileName
))
req
,
err
:=
s
.
client
.
NewRequest
(
"DELETE"
,
u
,
opt
,
options
)
if
err
!=
nil
{
...
...
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