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
31369e5a
Commit
31369e5a
authored
Jul 12, 2017
by
Jiangqi Zhang
Committed by
Sander van Harmelen
Aug 25, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Supports v4 get repository files (#183)
* Supports v4 get repository files * update exmaple of repository files
parent
bdd315a8
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
21 deletions
+16
-21
repository_files.go
examples/repository_files.go
+2
-3
repository_files.go
repository_files.go
+14
-18
No files found.
examples/repository_files.go
View file @
31369e5a
...
...
@@ -37,10 +37,9 @@ func repositoryFileExample() {
}
gf
:=
&
gitlab
.
GetFileOptions
{
FilePath
:
gitlab
.
String
(
file
.
FilePath
),
Ref
:
gitlab
.
String
(
"master"
),
Ref
:
gitlab
.
String
(
"master"
),
}
f
,
_
,
err
:=
git
.
RepositoryFiles
.
GetFile
(
"myname/myproject"
,
gf
)
f
,
_
,
err
:=
git
.
RepositoryFiles
.
GetFile
(
"myname/myproject"
,
file
.
FilePath
,
gf
)
if
err
!=
nil
{
log
.
Fatal
(
err
)
}
...
...
repository_files.go
View file @
31369e5a
...
...
@@ -24,16 +24,14 @@ import (
// RepositoryFilesService handles communication with the repository files
// related methods of the GitLab API.
//
// GitLab API docs:
// https://gitlab.com/gitlab-org/gitlab-ce/blob/8-16-stable/doc/api/repository_files.md
// GitLab API docs: https://docs.gitlab.com/ce/api/repository_files.html
type
RepositoryFilesService
struct
{
client
*
Client
}
// File represents a GitLab repository file.
//
// GitLab API docs:
// https://gitlab.com/gitlab-org/gitlab-ce/blob/8-16-stable/doc/api/repository_files.md
// GitLab API docs: https://docs.gitlab.com/ce/api/repository_files.html
type
File
struct
{
FileName
string
`json:"file_name"`
FilePath
string
`json:"file_path"`
...
...
@@ -52,23 +50,22 @@ func (r File) String() string {
// GetFileOptions represents the available GetFile() options.
//
// GitLab API docs:
// https://
gitlab.com/gitlab-org/gitlab-ce/blob/8-16-stable/doc/api/repository_files.md
#get-file-from-respository
// https://
docs.gitlab.com/ce/api/repository_files.html
#get-file-from-respository
type
GetFileOptions
struct
{
FilePath
*
string
`url:"file_path,omitempty" json:"file_path,omitempty"`
Ref
*
string
`url:"ref,omitempty" json:"ref,omitempty"`
Ref
*
string
`url:"ref,omitempty" json:"ref,omitempty"`
}
// GetFile allows you to receive information about a file in repository like
// name, size, content. Note that file content is Base64 encoded.
//
// GitLab API docs:
// https://
gitlab.com/gitlab-org/gitlab-ce/blob/8-16-stable/doc/api/repository_files.md
#get-file-from-respository
func
(
s
*
RepositoryFilesService
)
GetFile
(
pid
interface
{},
opt
*
GetFileOptions
,
options
...
OptionFunc
)
(
*
File
,
*
Response
,
error
)
{
// https://
docs.gitlab.com/ce/api/repository_files.html
#get-file-from-respository
func
(
s
*
RepositoryFilesService
)
GetFile
(
pid
interface
{},
fileName
string
,
opt
*
GetFileOptions
,
options
...
OptionFunc
)
(
*
File
,
*
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
(
"GET"
,
u
,
opt
,
options
)
if
err
!=
nil
{
...
...
@@ -86,8 +83,7 @@ func (s *RepositoryFilesService) GetFile(pid interface{}, opt *GetFileOptions, o
// FileInfo represents file details of a GitLab repository file.
//
// GitLab API docs:
// https://gitlab.com/gitlab-org/gitlab-ce/blob/8-16-stable/doc/api/repository_files.md
// GitLab API docs: https://docs.gitlab.com/ce/api/repository_files.html
type
FileInfo
struct
{
FilePath
string
`json:"file_path"`
BranchName
string
`json:"branch_name"`
...
...
@@ -100,7 +96,7 @@ func (r FileInfo) String() string {
// CreateFileOptions represents the available CreateFile() options.
//
// GitLab API docs:
// https://
gitlab.com/gitlab-org/gitlab-ce/blob/8-16-stable/doc/api/repository_files.md
#create-new-file-in-repository
// 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"`
...
...
@@ -114,7 +110,7 @@ type CreateFileOptions struct {
// CreateFile creates a new file in a repository.
//
// GitLab API docs:
// https://
gitlab.com/gitlab-org/gitlab-ce/blob/8-16-stable/doc/api/repository_files.md
#create-new-file-in-repository
// 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
)
{
project
,
err
:=
parseID
(
pid
)
if
err
!=
nil
{
...
...
@@ -139,7 +135,7 @@ func (s *RepositoryFilesService) CreateFile(pid interface{}, opt *CreateFileOpti
// UpdateFileOptions represents the available UpdateFile() options.
//
// GitLab API docs:
// https://
gitlab.com/gitlab-org/gitlab-ce/blob/8-16-stable/doc/api/repository_files.md
#update-existing-file-in-repository
// 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"`
...
...
@@ -153,7 +149,7 @@ type UpdateFileOptions struct {
// UpdateFile updates an existing file in a repository
//
// GitLab API docs:
// https://
gitlab.com/gitlab-org/gitlab-ce/blob/8-16-stable/doc/api/repository_files.md
#update-existing-file-in-repository
// 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
)
{
project
,
err
:=
parseID
(
pid
)
if
err
!=
nil
{
...
...
@@ -178,7 +174,7 @@ func (s *RepositoryFilesService) UpdateFile(pid interface{}, opt *UpdateFileOpti
// DeleteFileOptions represents the available DeleteFile() options.
//
// GitLab API docs:
// https://
gitlab.com/gitlab-org/gitlab-ce/blob/8-16-stable/doc/api/repository_files.md
#delete-existing-file-in-repository
// 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"`
...
...
@@ -190,7 +186,7 @@ type DeleteFileOptions struct {
// DeleteFile deletes an existing file in a repository
//
// GitLab API docs:
// https://
gitlab.com/gitlab-org/gitlab-ce/blob/8-16-stable/doc/api/repository_files.md
#delete-existing-file-in-repository
// 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
)
{
project
,
err
:=
parseID
(
pid
)
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