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
3f3acb6a
Commit
3f3acb6a
authored
Nov 12, 2018
by
Sander van Harmelen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update styling a bit
parent
729207a1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
41 additions
and
15 deletions
+41
-15
repository_files.go
repository_files.go
+41
-15
No files found.
repository_files.go
View file @
3f3acb6a
...
...
@@ -67,7 +67,11 @@ func (s *RepositoryFilesService) GetFile(pid interface{}, fileName string, opt *
if
err
!=
nil
{
return
nil
,
nil
,
err
}
u
:=
fmt
.
Sprintf
(
"projects/%s/repository/files/%s"
,
url
.
QueryEscape
(
project
),
url
.
PathEscape
(
fileName
))
u
:=
fmt
.
Sprintf
(
"projects/%s/repository/files/%s"
,
url
.
QueryEscape
(
project
),
url
.
PathEscape
(
fileName
),
)
req
,
err
:=
s
.
client
.
NewRequest
(
"GET"
,
u
,
opt
,
options
)
if
err
!=
nil
{
...
...
@@ -91,8 +95,8 @@ type GetFileMetaDataOptions struct {
Ref
*
string
`url:"ref,omitempty" json:"ref,omitempty"`
}
// GetFileMetaData allows you to receive meta information about a file in
repository like
// name, size.
// GetFileMetaData allows you to receive meta information about a file in
//
repository like
name, size.
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/repository_files.html#get-file-from-repository
...
...
@@ -101,25 +105,31 @@ func (s *RepositoryFilesService) GetFileMetaData(pid interface{}, fileName strin
if
err
!=
nil
{
return
nil
,
nil
,
err
}
u
:=
fmt
.
Sprintf
(
"projects/%s/repository/files/%s"
,
url
.
QueryEscape
(
project
),
url
.
PathEscape
(
fileName
))
u
:=
fmt
.
Sprintf
(
"projects/%s/repository/files/%s"
,
url
.
QueryEscape
(
project
),
url
.
PathEscape
(
fileName
),
)
req
,
err
:=
s
.
client
.
NewRequest
(
"HEAD"
,
u
,
opt
,
options
)
if
err
!=
nil
{
return
nil
,
nil
,
err
}
f
:=
new
(
File
)
resp
,
err
:=
s
.
client
.
Do
(
req
,
nil
)
if
err
!=
nil
{
return
nil
,
resp
,
err
}
f
.
BlobID
=
resp
.
Header
.
Get
(
"X-Gitlab-Blob-Id"
)
f
.
CommitID
=
resp
.
Header
.
Get
(
"X-Gitlab-Last-Commit-Id"
)
f
.
Encoding
=
resp
.
Header
.
Get
(
"X-Gitlab-Encoding"
)
f
.
FileName
=
resp
.
Header
.
Get
(
"X-Gitlab-File-Name"
)
f
.
FilePath
=
resp
.
Header
.
Get
(
"X-Gitlab-File-Path"
)
f
.
Ref
=
resp
.
Header
.
Get
(
"X-Gitlab-Ref"
)
f
:=
&
File
{
BlobID
:
resp
.
Header
.
Get
(
"X-Gitlab-Blob-Id"
),
CommitID
:
resp
.
Header
.
Get
(
"X-Gitlab-Last-Commit-Id"
),
Encoding
:
resp
.
Header
.
Get
(
"X-Gitlab-Encoding"
),
FileName
:
resp
.
Header
.
Get
(
"X-Gitlab-File-Name"
),
FilePath
:
resp
.
Header
.
Get
(
"X-Gitlab-File-Path"
),
Ref
:
resp
.
Header
.
Get
(
"X-Gitlab-Ref"
),
}
if
sizeString
:=
resp
.
Header
.
Get
(
"X-Gitlab-Size"
);
sizeString
!=
""
{
f
.
Size
,
err
=
strconv
.
Atoi
(
sizeString
)
if
err
!=
nil
{
...
...
@@ -147,7 +157,11 @@ func (s *RepositoryFilesService) GetRawFile(pid interface{}, fileName string, op
if
err
!=
nil
{
return
nil
,
nil
,
err
}
u
:=
fmt
.
Sprintf
(
"projects/%s/repository/files/%s/raw"
,
url
.
QueryEscape
(
project
),
url
.
PathEscape
(
fileName
))
u
:=
fmt
.
Sprintf
(
"projects/%s/repository/files/%s/raw"
,
url
.
QueryEscape
(
project
),
url
.
PathEscape
(
fileName
),
)
req
,
err
:=
s
.
client
.
NewRequest
(
"GET"
,
u
,
opt
,
options
)
if
err
!=
nil
{
...
...
@@ -197,7 +211,11 @@ func (s *RepositoryFilesService) CreateFile(pid interface{}, fileName string, op
if
err
!=
nil
{
return
nil
,
nil
,
err
}
u
:=
fmt
.
Sprintf
(
"projects/%s/repository/files/%s"
,
url
.
QueryEscape
(
project
),
url
.
PathEscape
(
fileName
))
u
:=
fmt
.
Sprintf
(
"projects/%s/repository/files/%s"
,
url
.
QueryEscape
(
project
),
url
.
PathEscape
(
fileName
),
)
req
,
err
:=
s
.
client
.
NewRequest
(
"POST"
,
u
,
opt
,
options
)
if
err
!=
nil
{
...
...
@@ -236,7 +254,11 @@ func (s *RepositoryFilesService) UpdateFile(pid interface{}, fileName string, op
if
err
!=
nil
{
return
nil
,
nil
,
err
}
u
:=
fmt
.
Sprintf
(
"projects/%s/repository/files/%s"
,
url
.
QueryEscape
(
project
),
url
.
PathEscape
(
fileName
))
u
:=
fmt
.
Sprintf
(
"projects/%s/repository/files/%s"
,
url
.
QueryEscape
(
project
),
url
.
PathEscape
(
fileName
),
)
req
,
err
:=
s
.
client
.
NewRequest
(
"PUT"
,
u
,
opt
,
options
)
if
err
!=
nil
{
...
...
@@ -272,7 +294,11 @@ func (s *RepositoryFilesService) DeleteFile(pid interface{}, fileName string, op
if
err
!=
nil
{
return
nil
,
err
}
u
:=
fmt
.
Sprintf
(
"projects/%s/repository/files/%s"
,
url
.
QueryEscape
(
project
),
url
.
PathEscape
(
fileName
))
u
:=
fmt
.
Sprintf
(
"projects/%s/repository/files/%s"
,
url
.
QueryEscape
(
project
),
url
.
PathEscape
(
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