Skip to content

Commit

Permalink
Merge d6dba6e into ce534e2
Browse files Browse the repository at this point in the history
  • Loading branch information
Raphaël Benitte committed Aug 25, 2016
2 parents ce534e2 + d6dba6e commit 0d930da
Show file tree
Hide file tree
Showing 57 changed files with 1,265 additions and 1,324 deletions.
1 change: 1 addition & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"presets": [
"es2015",
"stage-2",
"react"
]
}
11 changes: 7 additions & 4 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,13 @@
"plugins": [
"react"
],
"settings": {
"react": {
"version": "15.0"
}
},
"rules": {
"semi": 2,
"semi": [2, "never"],
"prefer-template": 2,
"indent": [2, 4, {
"SwitchCase": 1
Expand Down Expand Up @@ -52,9 +57,7 @@
"allowBind": false
}],
"react/no-direct-mutation-state": 2,
"react/no-deprecated": [2, {
"react": "0.13.3"
}],
"react/no-deprecated": [2],
"react/prop-types": [1, {}],
"react/react-in-jsx-scope": 2,
"react/prefer-es6-class": [2, "always"],
Expand Down
6 changes: 1 addition & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
language: node_js
node_js:
- '0.12'
- '4'
- '5'
before_install:
- npm install -g npm
- '6'
script:
- npm run eslint
- npm run test-cover
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
> - [Polish]

## v1.3.0 (2016-04-15)

* **New Feature**
* `widgets`: [#14](https://github.com/plouc/mozaik-ext-github/pull/14) Add ability to click on widgets github entities.


## v1.2.2 (2016-04-13)

* **Polish**
Expand Down
64 changes: 28 additions & 36 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mozaik-ext-github",
"version": "1.2.2",
"version": "2.0.0-alpha.1",
"description": "Mozaik github widgets",
"repository": {
"type": "git",
Expand All @@ -21,55 +21,50 @@
"dashboard"
],
"engines": {
"node": "0.12.x",
"node": ">=6.0.0",
"npm": ">=3.0.0"
},
"dependencies": {
"babelify": "7.2.0",
"babel-core": "6.7.6",
"babel-preset-es2015": "6.6.0",
"babel-preset-react": "6.5.0",
"bluebird": "3.3.5",
"bluebird": "3.4.1",
"chalk": "1.1.3",
"convict": "1.2.0",
"lodash": "4.10.0",
"moment": "2.12.0",
"convict": "1.4.0",
"lodash": "4.15.0",
"moment": "2.14.1",
"moment-duration-format": "1.3.0",
"react-mixin": "3.0.4",
"reflux": "0.4.1",
"superagent": "1.8.3",
"superagent-bluebird-promise": "3.0.0"
"nivo": "0.0.0",
"superagent": "2.2.0",
"superagent-bluebird-promise": "3.0.2"
},
"devDependencies": {
"ava": "0.14.0",
"babel-eslint": "6.0.2",
"babel-register": "6.7.2",
"coveralls": "2.11.9",
"enzyme": "2.2.0",
"eslint": "2.7.0",
"eslint-plugin-react": "4.3.0",
"mockery": "1.5.1",
"ava": "0.16.0",
"babel-core": "6.13.2",
"babel-eslint": "6.1.2",
"babel-preset-es2015": "6.13.2",
"babel-preset-react": "6.11.1",
"babel-register": "6.11.6",
"coveralls": "2.11.12",
"enzyme": "2.4.1",
"eslint": "3.3.1",
"eslint-plugin-react": "6.1.2",
"mockery": "1.7.0",
"nock": "8.0.0",
"nyc": "6.4.0",
"react": "^0.13.3",
"sinon": "1.17.3"
"nyc": "8.1.0",
"react": "15.3.1",
"react-addons-test-utils": "15.3.1",
"react-dom": "15.3.1",
"sinon": "1.17.5"
},
"peerDependencies": {
"mozaik": ">=1.4.2",
"react": "^0.13.3"
"mozaik": ">=2.0.0",
"react": ">=15.0.0"
},
"scripts": {
"eslint": "eslint --ext .js --ext .jsx ./src/** ./test/**",
"eslint": "eslint ./src/** ./test/**",
"test": "ava",
"test-cover": "nyc ava",
"coveralls": "nyc report --reporter=text-lcov | coveralls",
"cover-report": "nyc report --reporter=lcov && open coverage/lcov-report/index.html"
},
"browserify": {
"transform": [
"babelify"
]
},
"ava": {
"files": [
"test/**/*.test.js"
Expand All @@ -82,8 +77,5 @@
"babel": "inherit"
},
"nyc": {
"extension": [
".jsx"
]
}
}
127 changes: 69 additions & 58 deletions src/client.js
Original file line number Diff line number Diff line change
@@ -1,69 +1,80 @@
import request from 'superagent-bluebird-promise';
import Promise from 'bluebird';
import _ from 'lodash';
import chalk from 'chalk';
import config from './config';
const request = require('superagent-bluebird-promise')
const _ = require('lodash')
const chalk = require('chalk')
const config = require('./config')


/**
* @param {Mozaik} mozaik
*/
const client = mozaik => {

mozaik.loadApiConfig(config);
mozaik.loadApiConfig(config)

const buildApiRequest = (path, params) => {
const url = config.get('github.baseUrl');
const req = request.get(`${url}${path}`);
const url = config.get('github.baseUrl')
const req = request.get(`${url}${path}`)

const paramsDebug = params ? ` ${JSON.stringify(params)}` : '';
mozaik.logger.info(chalk.yellow(`[github] calling ${url}${path}${paramsDebug}`));
const paramsDebug = params ? ` ${JSON.stringify(params)}` : ''
mozaik.logger.info(chalk.yellow(`[github] calling ${url}${path}${paramsDebug}`))

if (params) {
req.query(params);
req.query(params)
}

if (config.get('github.token') !== '') {
req.set('Authorization', `token ${config.get('github.token')}`);
req.set('Authorization', `token ${config.get('github.token')}`)
}

return req.promise();
};
return req.promise()
}

const repositoryCommits = (params, buffer) => {
return buildApiRequest(`/repos/${params.repository}/commits`, params)
.then(res => {
buffer.commits = buffer.commits.concat(res.body);
buffer.commits = buffer.commits.concat(res.body)

// checks if there's an available next page in response link http header
if (res.headers.link && /&page=(\d+)>; rel="next"/.test(res.headers.link) === true && buffer.commits.length < buffer.max) {
buffer.page = parseInt(/&page=(\d+)>; rel="next"/.exec(res.headers.link)[1]);
if (res.headers.link && /&page=(\d+)> rel="next"/.test(res.headers.link) === true && buffer.commits.length < buffer.max) {
buffer.page = parseInt(/&page=(\d+)> rel="next"/.exec(res.headers.link)[1])

return repositoryCommits(params, buffer);
return repositoryCommits(params, buffer)
} else {
return buffer.commits;
return buffer.commits
}
})
;
};

}

const apiCalls = {
organization(params) {
return buildApiRequest(`/orgs/${params.organization}`)
organization({ organization }) {
return buildApiRequest(`/orgs/${organization}`)
.then(res => res.body)
;

},

user(params) {
return buildApiRequest(`/users/${params.user}`)
user({ user }) {
return buildApiRequest(`/users/${user}`)
.then(res => res.body)
;

},

pullRequests(params) {
return buildApiRequest(`/repos/${params.repository}/pulls`)
pullRequests({ repository }) {
return buildApiRequest(`/repos/${repository}/pulls`)
.then(res => res.body)
;

},

repositoryParticipationStats({ repository }) {
return buildApiRequest(`/repos/${repository}/stats/participation`)
.then(res => res.body)

},

repositoryLanguages({ repository }) {
return buildApiRequest(`/repos/${repository}/languages`)
.then(res => res.body)

},

// Be warned that this API call can be heavy enough
Expand All @@ -72,22 +83,22 @@ const client = mozaik => {
return buildApiRequest(`/repos/${params.repository}/branches`)
.then(res => {
return Promise.all(res.body.map(branch => {
return apiCalls.branch(_.extend({ branch: branch.name }, params));
}));
return apiCalls.branch(_.extend({ branch: branch.name }, params))
}))
})
;

},

branch(params) {
return buildApiRequest(`/repos/${params.repository}/branches/${params.branch}`)
branch({ repository, branch }) {
return buildApiRequest(`/repos/${repository}/branches/${branch}`)
.then(res => res.body)
;

},

repositoryContributorsStats(params) {
return buildApiRequest(`/repos/${params.repository}/stats/contributors`)
repositoryContributorsStats({ repository }) {
return buildApiRequest(`/repos/${repository}/stats/contributors`)
.then(res => res.body)
;

},

repositoryCommits(params) {
Expand All @@ -97,23 +108,23 @@ const client = mozaik => {
max: 1000
})
.then(commits => {
return commits;
return commits
})
;

},

issues(params) {
return buildApiRequest(`/repos/${params.repository}/issues`)
issues({ repository }) {
return buildApiRequest(`/repos/${repository}/issues`)
.then(res => res.body)
;

},

// Be warned that this API call can be heavy enough
// because it fetch all the issues for each labels
issueLabelsAggregations(params) {
params.labels.forEach(label => {
label.count = 0;
});
label.count = 0
})

return Promise.all(params.labels.map(label => {
return buildApiRequest(`/repos/${params.repository}/issues`, {
Expand All @@ -122,28 +133,28 @@ const client = mozaik => {
filter: 'all'
})
.then(res => {
label.count = res.body.length;
label.count = res.body.length

return label;
return label
})
;
}));

}))
},

status() {
const url = 'https://status.github.com/api/last-message.json';
let req = request.get(url);
const url = 'https://status.github.com/api/last-message.json'
let req = request.get(url)

mozaik.logger.info(chalk.yellow(`[github] calling ${url}`));
mozaik.logger.info(chalk.yellow(`[github] calling ${url}`))

return req.promise()
.then(res => res.body)
;

}
};
}

return apiCalls;
};
return apiCalls
}


export default client;
module.exports = client

0 comments on commit 0d930da

Please sign in to comment.