1 /* This file is part of NIT ( http://www.nitlanguage.org ).
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
7 http://www.apache.org/licenses/LICENSE-2.0
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
15 Documentation generator for the nit language.
16 Generate API documentation in HTML format from nit source code.
20 * GitHub API wrapper for github plugin
25 ], function($
, Base64
) {
28 // try to login the user to github API
29 login
: function(user
) {
32 beforeSend
: function (xhr
) {
33 xhr
.setRequestHeader ("Authorization", user
.auth
);
36 url
: "https://api.github.com/repos/" + user
.login
+ "/" + user
.repo
,
43 user
.infos
= this.getUserInfos(user
);
44 user
.signedOff
= this.getSignedOff(user
)
48 // request for user github account infos
49 getUserInfos
: function(user
) {
52 beforeSend
: function (xhr
) {
53 xhr
.setRequestHeader ("Authorization", user
.auth
);
56 url
: "https://api.github.com/users/" + user
.login
,
59 success
: function(response
) {
62 error
: function(response
) {
69 // build signedoff user default signature
70 getSignedOff
: function(user
) {
71 return user
.infos
.name
+ " <" + user
.infos
.email
+ ">";
74 // get the branches list from a repo
75 getBranches
: function(user
) {
78 beforeSend
: function (xhr
) {
79 xhr
.setRequestHeader ("Authorization", user
.auth
);
82 url
: "https://api.github.com/repos/" + user
.login
+ "/" + user
.repo
+ "/branches",
85 success
: function(response
) {
88 error
: function(response
) {
97 // get the latest commit on `branchName`
98 getCommit
: function(user
, sha
) {
101 beforeSend
: function (xhr
) {
102 xhr
.setRequestHeader ("Authorization", user
.auth
);
105 url
: "https://api.github.com/repos/" + user
.login
+ "/" + user
.repo
+ "/git/commits/" + sha
,
108 success
: function(response
) {
111 error
: function(response
) {
118 // get the base tree for a commit sha
119 getTree
: function(user
, sha
) {
122 beforeSend
: function (xhr
) {
123 xhr
.setRequestHeader ("Authorization", user
.auth
);
126 url
: "https://api.github.com/repos/" + user
.login
+ "/" + user
.repo
+ "/git/trees/" + sha
+ "?recursive=1",
129 success
: function(response
) {
132 error
: function(response
) {
140 createBlob
: function(user
, content
) {
143 beforeSend
: function (xhr
) {
144 xhr
.setRequestHeader ("Authorization", user
.auth
);
147 url
: "https://api.github.com/repos/" + user
.login
+ "/" + user
.repo
+ "/git/blobs",
150 data
: JSON
.stringify({
151 content
: Base64
.encode(content
),
154 success
: function(response
) {
157 error
: function(response
) {
164 // create a new tree from a base tree
165 createTree
: function(user
, baseTree
, path
, blob
) {
168 beforeSend
: function (xhr
) {
169 xhr
.setRequestHeader ("Authorization", user
.auth
);
172 url
: "https://api.github.com/repos/" + user
.login
+ "/" + user
.repo
+ "/git/trees",
173 data
: JSON
.stringify({
174 base_tree
: baseTree
.sha
,
177 mode
: "100644", // file (blob)
184 success
: function(response
) {
187 error
: function(response
) {
194 // create a new commit
195 createCommit
: function(user
, message
, parentCommit
, tree
) {
198 beforeSend
: function (xhr
) {
199 xhr
.setRequestHeader ("Authorization", user
.auth
);
202 url
: "https://api.github.com/repos/" + user
.login
+ "/" + user
.repo
+ "/git/commits",
203 data
: JSON
.stringify({
205 parents
: parentCommit
,
210 success
: function(response
) {
213 error
: function(response
) {
220 // create a pull request
221 createPullRequest
: function(user
, title
, body
, origin
, head
) {
224 beforeSend
: function (xhr
) {
225 xhr
.setRequestHeader ("Authorization", user
.auth
);
228 url
: "https://api.github.com/repos/" + origin
.user
+ "/" + origin
.repo
+ "/pulls",
229 data
: JSON
.stringify({
233 head
: user
.login
+ ":" + head
237 success
: function(response
) {
240 error
: function(response
) {
247 // update a pull request
248 updatePullRequest
: function(user
, title
, body
, state
, request
) {
251 beforeSend
: function (xhr
) {
252 xhr
.setRequestHeader ("Authorization", user
.auth
);
256 data
: JSON
.stringify({
263 success
: function(response
) {
266 error
: function(response
) {
275 getFile
: function(user
, path
, branch
) {
279 url
: "https://api.github.com/repos/" + user
.login
+ "/" + user
.repo
+ "/contents/" + path
,
285 success
: function(response
) {
288 error
: function(response
) {