Skip to content

Commit ae33f7b

Browse files
committed
add repository files api
1 parent a8abce8 commit ae33f7b

14 files changed

+411
-34
lines changed

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
lib-cov
22
coverage.html
3-
test/config.js
43
*.seed
54
*.log
65
*.csv
@@ -14,4 +13,4 @@ logs
1413
results
1514

1615
node_modules
17-
npm-debug.log
16+
npm-debug.log

.jshintignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules/
2+
coverage/
3+
.tmp/
4+
.git/

.jshintrc

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
{
2+
// JSHint Default Configuration File (as on JSHint website)
3+
// See http://jshint.com/docs/ for more details
4+
5+
"maxerr" : 50, // {int} Maximum error before stopping
6+
7+
// Enforcing
8+
"bitwise" : true, // true: Prohibit bitwise operators (&, |, ^, etc.)
9+
"camelcase" : false, // true: Identifiers must be in camelCase
10+
"curly" : true, // true: Require {} for every new block or scope
11+
"eqeqeq" : true, // true: Require triple equals (===) for comparison
12+
"forin" : false, // true: Require filtering for..in loops with obj.hasOwnProperty()
13+
"immed" : false, // true: Require immediate invocations to be wrapped in parens e.g. `(function () { } ());`
14+
"indent" : false, // {int} Number of spaces to use for indentation
15+
"latedef" : false, // true: Require variables/functions to be defined before being used
16+
"newcap" : false, // true: Require capitalization of all constructor functions e.g. `new F()`
17+
"noarg" : true, // true: Prohibit use of `arguments.caller` and `arguments.callee`
18+
"noempty" : true, // true: Prohibit use of empty blocks
19+
"nonew" : false, // true: Prohibit use of constructors for side-effects (without assignment)
20+
"plusplus" : false, // true: Prohibit use of `++` & `--`
21+
"quotmark" : false, // Quotation mark consistency:
22+
// false : do nothing (default)
23+
// true : ensure whatever is used is consistent
24+
// "single" : require single quotes
25+
// "double" : require double quotes
26+
"undef" : true, // true: Require all non-global variables to be declared (prevents global leaks)
27+
"unused" : false, // true: Require all defined variables be used
28+
"strict" : true, // true: Requires all functions run in ES5 Strict Mode
29+
"trailing" : false, // true: Prohibit trailing whitespaces
30+
"maxparams" : false, // {int} Max number of formal params allowed per function
31+
"maxdepth" : false, // {int} Max depth of nested blocks (within functions)
32+
"maxstatements" : false, // {int} Max number statements per function
33+
"maxcomplexity" : false, // {int} Max cyclomatic complexity per function
34+
"maxlen" : false, // {int} Max number of characters per line
35+
36+
// Relaxing
37+
"asi" : false, // true: Tolerate Automatic Semicolon Insertion (no semicolons)
38+
"boss" : true, // true: Tolerate assignments where comparisons would be expected
39+
"debug" : false, // true: Allow debugger statements e.g. browser breakpoints.
40+
"eqnull" : false, // true: Tolerate use of `== null`
41+
"es5" : false, // true: Allow ES5 syntax (ex: getters and setters)
42+
"esnext" : true, // true: Allow ES.next (ES6) syntax (ex: `const`)
43+
"moz" : false, // true: Allow Mozilla specific syntax (extends and overrides esnext features)
44+
// (ex: `for each`, multiple try/catch, function expression…)
45+
"evil" : false, // true: Tolerate use of `eval` and `new Function()`
46+
"expr" : true, // true: Tolerate `ExpressionStatement` as Programs
47+
"funcscope" : false, // true: Tolerate defining variables inside control statements"
48+
"globalstrict" : false, // true: Allow global "use strict" (also enables 'strict')
49+
"iterator" : false, // true: Tolerate using the `__iterator__` property
50+
"lastsemic" : false, // true: Tolerate omitting a semicolon for the last statement of a 1-line block
51+
"laxbreak" : true, // true: Tolerate possibly unsafe line breakings
52+
"laxcomma" : false, // true: Tolerate comma-first style coding
53+
"loopfunc" : false, // true: Tolerate functions being defined in loops
54+
"multistr" : true, // true: Tolerate multi-line strings
55+
"proto" : false, // true: Tolerate using the `__proto__` property
56+
"scripturl" : false, // true: Tolerate script-targeted URLs
57+
"smarttabs" : false, // true: Tolerate mixed tabs/spaces when used for alignment
58+
"shadow" : true, // true: Allows re-define variables later in code e.g. `var x=1; x=2;`
59+
"sub" : false, // true: Tolerate using `[]` notation when it can still be expressed in dot notation
60+
"supernew" : false, // true: Tolerate `new function () { ... };` and `new Object;`
61+
"validthis" : true, // true: Tolerate using this in a non-constructor function
62+
63+
// Environments
64+
"browser" : true, // Web Browser (window, document, etc)
65+
"couch" : false, // CouchDB
66+
"devel" : true, // Development/debugging (alert, confirm, etc)
67+
"dojo" : false, // Dojo Toolkit
68+
"jquery" : false, // jQuery
69+
"mootools" : false, // MooTools
70+
"node" : true, // Node.js
71+
"nonstandard" : false, // Widely adopted globals (escape, unescape, etc)
72+
"prototypejs" : false, // Prototype and Scriptaculous
73+
"rhino" : false, // Rhino
74+
"worker" : false, // Web Workers
75+
"wsh" : false, // Windows Scripting Host
76+
"yui" : false, // Yahoo User Interface
77+
"noyield" : true, // allow generators without a yield
78+
79+
// Legacy
80+
"nomen" : false, // true: Prohibit dangling `_` in variables
81+
"onevar" : false, // true: Allow only one `var` statement per function
82+
"passfail" : false, // true: Stop on first error
83+
"white" : false, // true: Check against strict whitespace and indentation rules
84+
85+
// Custom Globals
86+
"globals" : { // additional predefined global variables
87+
// mocha
88+
"describe": true,
89+
"it": true,
90+
"before": true,
91+
"afterEach": true,
92+
"beforeEach": true,
93+
"after": true
94+
}
95+
}

.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ lib-cov/
44
Makefile
55
.travis.yml
66
logo.png
7+
.jshint*

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
language: node_js
22
node_js:
33
- '0.10'
4-
- '0.11'
54
script: make test-coveralls

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
TESTS = test/*.test.js
22
REPORTER = spec
3-
TIMEOUT = 10000
3+
TIMEOUT = 16000
44
MOCHA_OPTS =
55

66
install:

README.md

Lines changed: 60 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -173,21 +173,68 @@ Repository.prototype.getTree = function (params, callback);
173173
Repository.prototype.getBlob = function (params, callback);
174174
```
175175

176-
## Authors
177-
178-
```bash
179-
$ git summary
180-
181-
project : gitlab
182-
repo age : 5 months
183-
active : 11 days
184-
commits : 22
185-
files : 26
186-
authors :
187-
20 fengmk2 90.9%
188-
2 Ondrej 9.1%
176+
### RepositoryFiles
177+
178+
https://gitlab.com/help/api/repository_files
179+
180+
#### client.repositoryFiles.get({id, file_path, ref})
181+
182+
Get file from repository.
183+
Allows you to receive information about file in repository like name, size, content.
184+
Note that file content is Base64 encoded.
185+
186+
```json
187+
{
188+
"file_name": "key.rb",
189+
"file_path": "app/models/key.rb",
190+
"size": 1476,
191+
"encoding": "base64",
192+
"content": "IyA9PSBTY2hlbWEgSW5mb3...",
193+
"ref": "master",
194+
"blob_id": "79f7bbd25901e8334750839545a9bd021f0e4c83",
195+
"commit_id": "d5a3ff139356ce33e37e73add446f16869741b50"
196+
}
189197
```
190198

199+
Parameters:
200+
201+
* {String} file_path (required) - Full path to new file. Ex. lib/class.rb
202+
* {String} ref (required) - The name of branch, tag or commit
203+
204+
#### client.repositoryFiles.create({id, file_path, branch_name, encoding, content, commit_message})
205+
206+
Create new file in repository
207+
208+
Parameters:
209+
210+
* {String} file_path (required) - Full path to new file. Ex. lib/class.rb
211+
* {String} branch_name (required) - The name of branch
212+
* {String} encoding (optional) - 'text' or 'base64'. Text is default.
213+
* {String} content (required) - File content
214+
* {String} commit_message (required) - Commit message
215+
216+
#### client.repositoryFiles.update({id, file_path, branch_name, encoding, content, commit_message})
217+
218+
Update existing file in repository
219+
220+
Parameters:
221+
222+
* {String} file_path (required) - Full path to new file. Ex. lib/class.rb
223+
* {String} branch_name (required) - The name of branch
224+
* {String} encoding (optional) - 'text' or 'base64'. Text is default.
225+
* {String} content (required) - New file content
226+
* {String} commit_message (required) - Commit message
227+
228+
#### client.repositoryFiles.remove({id, file_path, branch_name, commit_message})
229+
230+
Delete existing file in repository
231+
232+
Parameters:
233+
234+
* {String} file_path (required) - Full path to new file. Ex. lib/class.rb
235+
* {String} branch_name (required) - The name of branch
236+
* {String} commit_message (required) - Commit message
237+
191238
## License
192239

193240
(The MIT License)

lib/gitlab.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,11 @@ var Issue = require('./issue');
2222
var User = require('./user');
2323
var Repository = require('./repository');
2424
var MergeRequest = require('./merge_request');
25+
var RepositoryFile = require('./repository_file');
2526

2627
/**
2728
* Create a gitlab API client.
28-
*
29+
*
2930
* @param {Object} options
3031
* - {String} api, api root url, e.g.: 'http://gitlab.com/api/v3'
3132
* - {String} privateToken, You can find or reset your private token in your profile.
@@ -43,11 +44,12 @@ function Gitlab(options) {
4344
this.globalHooks = new GlobalHook(this);
4445
this.issues = new Issue(this);
4546
this.users = new User(this);
46-
this.merge_requests = new MergeRequest(this);
47+
this.merge_requests = this.mergeRequests = new MergeRequest(this);
4748

4849
this.addResources({
4950
projects: Project,
5051
repository: Repository,
52+
repositoryFiles: RepositoryFile,
5153
});
5254
}
5355

lib/repository_file.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**!
2+
* gitlab - lib/repository_file.js
3+
*
4+
* Copyright(c) fengmk2 and other contributors.
5+
* MIT Licensed
6+
*
7+
* Authors:
8+
* fengmk2 <[email protected]> (http://fengmk2.github.com)
9+
*/
10+
11+
'use strict';
12+
13+
/**
14+
* Module dependencies.
15+
*/
16+
17+
var util = require('util');
18+
var restful = require('restful-client');
19+
20+
module.exports = RepositoryFile;
21+
22+
function RepositoryFile(client) {
23+
this.constructor.super_.call(this, client, '/projects/:id/repository/files');
24+
}
25+
util.inherits(RepositoryFile, restful.RESTFulResource);

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
},
1111
"dependencies": {
1212
"debug": "~0.8.1",
13-
"restful-client": "~0.0.4"
13+
"restful-client": "~0.1.0"
1414
},
1515
"devDependencies": {
1616
"autod": "*",
@@ -20,7 +20,7 @@
2020
"mocha": "*",
2121
"mocha-lcov-reporter": "*",
2222
"pedding": "~0.0.3",
23-
"should": "~3.3.1",
23+
"should": "~3.3.2",
2424
"travis-cov": "*"
2525
},
2626
"homepage": "https://github.com/repo-utils/gitlab",

0 commit comments

Comments
 (0)