@@ -41,11 +41,34 @@ func (s *contentService) Find(ctx context.Context, repo, path, ref string) (*scm
41
41
}
42
42
43
43
func (s * contentService ) Create (ctx context.Context , repo , path string , params * scm.ContentParams ) (* scm.Response , error ) {
44
- return nil , scm .ErrNotSupported
44
+ path = url .QueryEscape (path )
45
+ path = strings .Replace (path , "." , "%2E" , - 1 )
46
+ endpoint := fmt .Sprintf ("api/v4/projects/%s/repository/files/%s" , encode (repo ), path )
47
+ in := new (createUpdateContent )
48
+ in .Branch = params .Branch
49
+ in .Content = params .Data
50
+ in .CommitMessage = params .Message
51
+ in .Encoding = "base64"
52
+ in .AuthorEmail = params .Signature .Email
53
+ in .AuthorName = params .Signature .Name
54
+ res , err := s .client .do (ctx , "POST" , endpoint , in , nil )
55
+ return res , err
56
+
45
57
}
46
58
47
59
func (s * contentService ) Update (ctx context.Context , repo , path string , params * scm.ContentParams ) (* scm.Response , error ) {
48
- return nil , scm .ErrNotSupported
60
+ path = url .QueryEscape (path )
61
+ path = strings .Replace (path , "." , "%2E" , - 1 )
62
+ endpoint := fmt .Sprintf ("api/v4/projects/%s/repository/files/%s" , encode (repo ), path )
63
+ in := new (createUpdateContent )
64
+ in .Branch = params .Branch
65
+ in .Content = params .Data
66
+ in .CommitMessage = params .Message
67
+ in .Encoding = "base64"
68
+ in .AuthorEmail = params .Signature .Email
69
+ in .AuthorName = params .Signature .Name
70
+ res , err := s .client .do (ctx , "PUT" , endpoint , in , nil )
71
+ return res , err
49
72
}
50
73
51
74
func (s * contentService ) Delete (ctx context.Context , repo , path , ref string ) (* scm.Response , error ) {
@@ -71,6 +94,15 @@ type content struct {
71
94
LastCommitID string `json:"last_commit_id"`
72
95
}
73
96
97
+ type createUpdateContent struct {
98
+ Branch string `json:"branch"`
99
+ Content []byte `json:"content"`
100
+ CommitMessage string `json:"commit_message"`
101
+ Encoding string `json:"encoding"`
102
+ AuthorEmail string `json:"author_email"`
103
+ AuthorName string `json:"author_name"`
104
+ }
105
+
74
106
type object struct {
75
107
Path string `json:"path"`
76
108
Mode string `json:"mode"`
0 commit comments