@@ -52,6 +52,96 @@ public function show($username, $repository, $path = null, $reference = null)
52
52
));
53
53
}
54
54
55
+ /**
56
+ * Creates a new file in a repository
57
+ * @link http://developer.github.com/v3/repos/contents/#create-a-file
58
+ *
59
+ * @param string $username the user who owns the repository
60
+ * @param string $repository the name of the repository
61
+ * @param string $path path to file
62
+ * @param string $content contents of the new file
63
+ * @param string $message the commit message
64
+ * @param null|string $branch name of a branch
65
+ *
66
+ * @return array information about the new file
67
+ */
68
+ public function create ($ username , $ repository , $ path , $ content , $ message , $ branch = null )
69
+ {
70
+ $ url = 'repos/ ' .rawurlencode ($ username ).'/ ' .rawurlencode ($ repository ).'/contents/ ' .rawurlencode ($ path );
71
+
72
+ $ parameters = array (
73
+ 'content ' => base64_encode ($ content ),
74
+ 'message ' => $ message ,
75
+ );
76
+
77
+ if (null !== $ branch ) {
78
+ $ parameters ['branch ' ] = $ branch ;
79
+ }
80
+
81
+ return $ this ->put ($ url , $ parameters );
82
+ }
83
+
84
+ /**
85
+ * Updates the contents of a file in a repository
86
+ * @link http://developer.github.com/v3/repos/contents/#update-a-file
87
+ *
88
+ * @param string $username the user who owns the repository
89
+ * @param string $repository the name of the repository
90
+ * @param string $path path to file
91
+ * @param string $content contents of the new file
92
+ * @param string $message the commit message
93
+ * @param string $sha blob SHA of the file being replaced
94
+ * @param null|string $branch name of a branch
95
+ *
96
+ * @return array information about the updated file
97
+ */
98
+ public function update ($ username , $ repository , $ path , $ content , $ message , $ sha , $ branch = null )
99
+ {
100
+ $ url = 'repos/ ' .rawurlencode ($ username ).'/ ' .rawurlencode ($ repository ).'/contents/ ' .rawurlencode ($ path );
101
+
102
+ $ parameters = array (
103
+ 'content ' => base64_encode ($ content ),
104
+ 'message ' => $ message ,
105
+ 'sha ' => $ sha ,
106
+ );
107
+
108
+ if (null !== $ branch ) {
109
+ $ parameters ['branch ' ] = $ branch ;
110
+ }
111
+
112
+ return $ this ->put ($ url , $ parameters );
113
+ }
114
+
115
+
116
+ /**
117
+ * Deletes a file from a repository
118
+ * @link http://developer.github.com/v3/repos/contents/#delete-a-file
119
+ *
120
+ * @param string $username the user who owns the repository
121
+ * @param string $repository the name of the repository
122
+ * @param string $path path to file
123
+ * @param string $message the commit message
124
+ * @param string $sha blob SHA of the file being deleted
125
+ * @param null|string $branch name of a branch
126
+ *
127
+ * @return array information about the updated file
128
+ */
129
+ public function rm ($ username , $ repository , $ path , $ message , $ sha , $ branch = null )
130
+ {
131
+ $ url = 'repos/ ' .rawurlencode ($ username ).'/ ' .rawurlencode ($ repository ).'/contents/ ' .rawurlencode ($ path );
132
+
133
+ $ parameters = array (
134
+ 'message ' => $ message ,
135
+ 'sha ' => $ sha ,
136
+ );
137
+
138
+ if (null !== $ branch ) {
139
+ $ parameters ['branch ' ] = $ branch ;
140
+ }
141
+
142
+ return $ this ->delete ($ url , $ parameters );
143
+ }
144
+
55
145
/**
56
146
* Get content of archives in a repository
57
147
* @link http://developer.github.com/v3/repos/contents/
0 commit comments