@@ -41,11 +41,34 @@ func (s *contentService) Find(ctx context.Context, repo, path, ref string) (*scm
4141}
4242
4343func (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+
4557}
4658
4759func (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
4972}
5073
5174func (s * contentService ) Delete (ctx context.Context , repo , path , ref string ) (* scm.Response , error ) {
@@ -71,6 +94,15 @@ type content struct {
7194 LastCommitID string `json:"last_commit_id"`
7295}
7396
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+
74106type object struct {
75107 Path string `json:"path"`
76108 Mode string `json:"mode"`
0 commit comments