88 "context"
99 "encoding/base64"
1010 "fmt"
11- "time"
12-
1311 "github.com/drone/go-scm/scm"
1412)
1513
@@ -29,11 +27,44 @@ func (s *contentService) Find(ctx context.Context, repo, path, ref string) (*scm
2927}
3028
3129func (s * contentService ) Create (ctx context.Context , repo , path string , params * scm.ContentParams ) (* scm.Response , error ) {
32- return nil , scm .ErrNotSupported
30+ endpoint := fmt .Sprintf ("repos/%s/contents/%s" , repo , path )
31+ in := & contentCreateUpdate {
32+ Message : params .Message ,
33+ Branch : params .Branch ,
34+ Content : params .Data ,
35+ Sha : params .Sha ,
36+ Committer : commitAuthor {
37+ Name : params .Signature .Name ,
38+ Email : params .Signature .Email ,
39+ },
40+ Author : commitAuthor {
41+ Name : params .Signature .Name ,
42+ Email : params .Signature .Email ,
43+ },
44+ }
45+
46+ res , err := s .client .do (ctx , "PUT" , endpoint , in , nil )
47+ return res , err
3348}
3449
3550func (s * contentService ) Update (ctx context.Context , repo , path string , params * scm.ContentParams ) (* scm.Response , error ) {
36- return nil , scm .ErrNotSupported
51+ endpoint := fmt .Sprintf ("repos/%s/contents/%s" , repo , path )
52+ in := & contentCreateUpdate {
53+ Message : params .Message ,
54+ Branch : params .Branch ,
55+ Content : params .Data ,
56+ Sha : params .Sha ,
57+ Committer : commitAuthor {
58+ Name : params .Signature .Name ,
59+ Email : params .Signature .Email ,
60+ },
61+ Author : commitAuthor {
62+ Name : params .Signature .Name ,
63+ Email : params .Signature .Email ,
64+ },
65+ }
66+ res , err := s .client .do (ctx , "PUT" , endpoint , in , nil )
67+ return res , err
3768}
3869
3970func (s * contentService ) Delete (ctx context.Context , repo , path , ref string ) (* scm.Response , error ) {
@@ -55,20 +86,18 @@ type content struct {
5586 Type string `json:"type"`
5687}
5788
58- type contentUpdate struct {
59- Sha string `json:"sha"`
60- Message string `json:"message"`
61- HTMLURL string `json:"html_url"`
62- Author struct {
63- Name string `json:"name"`
64- Email string `json:"email"`
65- Date time.Time `json:"date"`
66- } `json:"author"`
67- Committer struct {
68- Name string `json:"name"`
69- Email string `json:"email"`
70- Date time.Time `json:"date"`
71- } `json:"committer"`
89+ type contentCreateUpdate struct {
90+ Branch string `json:"branch"`
91+ Message string `json:"message"`
92+ Content []byte `json:"content"`
93+ Sha string `json:"sha"`
94+ Author commitAuthor `json:"author"`
95+ Committer commitAuthor `json:"committer"`
96+ }
97+
98+ type commitAuthor struct {
99+ Name string `json:"name"`
100+ Email string `json:"email"`
72101}
73102
74103func convertContentInfoList (from []* content ) []* scm.ContentInfo {
0 commit comments