├── .babelrc ├── .eslintignore ├── .eslintrc.yml ├── .github └── ISSUE_TEMPLATE.md ├── .gitignore ├── .lintstagedrc ├── .npmignore ├── .prettierrc.yml ├── .travis.yml ├── CHANGELOG.md ├── LICENSE.md ├── README.md ├── client.js ├── commitlint.config.js ├── package.json ├── preview ├── github.branches.png ├── github.issue_labels_donut.png ├── github.issue_types_treemap.png ├── github.organization_badge.png ├── github.repository_contributors_stats.png ├── github.status.png └── github.user_badge.png ├── src ├── client.js ├── components │ ├── Branch.js │ ├── Branches.js │ ├── Status.js │ ├── badges │ │ ├── OrgBadge.js │ │ ├── RepoBadge.js │ │ └── UserBadge.js │ ├── index.js │ ├── pull-requests │ │ ├── PullRequest.js │ │ └── PullRequests.js │ ├── stats │ │ ├── RepoCommitActivity.js │ │ ├── RepoCommitActivityHistogram.js │ │ ├── RepoCommitActivityLine.js │ │ ├── RepoContributorStat.js │ │ ├── RepoContributorsStats.js │ │ └── charts │ │ │ ├── RepoCommitActivityHistogramChart.js │ │ │ └── RepoCommitActivityLineChart.js │ └── traffic │ │ ├── RepoTrafficClones.js │ │ ├── RepoTrafficClonesHistogram.js │ │ ├── RepoTrafficClonesLine.js │ │ ├── RepoTrafficViews.js │ │ ├── RepoTrafficViewsHistogram.js │ │ ├── RepoTrafficViewsLine.js │ │ └── charts │ │ ├── RepoTrafficClonesHistogramChart.js │ │ ├── RepoTrafficClonesLineChart.js │ │ ├── RepoTrafficViewsHistogramChart.js │ │ └── RepoTrafficViewsLineChart.js └── config.js ├── test ├── .eslintrc.yml ├── components │ ├── badges │ │ ├── OrgBadge.test.js │ │ ├── UserBadge.test.js │ │ └── __snapshots__ │ │ │ ├── OrgBadge.test.js.snap │ │ │ └── UserBadge.test.js.snap │ └── pull-requests │ │ ├── PullRequests.test.js │ │ └── __snapshots__ │ │ └── PullRequests.test.js.snap └── setupTests.js └── yarn.lock /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": ["@mozaik/babel-preset"] 3 | } 4 | -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | *.snap -------------------------------------------------------------------------------- /.eslintrc.yml: -------------------------------------------------------------------------------- 1 | parser: babel-eslint 2 | parserOptions: 3 | ecmaVersion: 6 4 | sourceType: module 5 | ecmaFeatures: 6 | jsx: true 7 | env: 8 | browser: true 9 | node: true 10 | es6: true 11 | extends: 12 | - eslint:recommended 13 | - plugin:react/recommended 14 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | item | info | notes 2 | ------------------------------|------------|--------------------------------------------------------------------------------------------- 3 | **node** version | | *output from `node --version`* 4 | **npm** version | | *output from `npm --version`* 5 | **mozaik-ext-github** version | | *available in project's `package.json`* 6 | **mozaik** version | | *available in project's `package.json`* 7 | **mozaik-demo** version | | *version of the demo used, depends on which method you used to setup your Mozaïk dashboard* 8 | **component** | | *name of the extension's component or `client` if it's related to the extension's client* 9 | **browser** | | *browser used, applyable if the issue is not related to the client* 10 | 11 | ## Expected behavior 12 | 13 | *Description of the expected behavior.* 14 | 15 | ## Actual behavior 16 | 17 | *Description of the actual behavior.* 18 | 19 | ## Steps to reproduce 20 | 21 | *Description of the various steps required to reproduce the error.* 22 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .idea 3 | *.log* 4 | /.nyc_output 5 | /coverage 6 | /lib 7 | /es 8 | /node_modules -------------------------------------------------------------------------------- /.lintstagedrc: -------------------------------------------------------------------------------- 1 | { 2 | "*.js": [ 3 | "eslint --fix ./src/** ./test/**", 4 | "prettier --color --write \"{src,test}/**/*.js\" 'client.js'", 5 | "git add", 6 | "jest --bail --findRelatedTests" 7 | ] 8 | } -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | # Doc 2 | /preview 3 | 4 | # config 5 | .babelrc 6 | .eslintignore 7 | .eslintrc.yml 8 | .gitignore 9 | .lintstagedrc 10 | .npmignore 11 | .prettierignore 12 | .prettierrc.yml 13 | .travis.yml 14 | commitlint.config.js 15 | 16 | # Logs 17 | *.log* 18 | 19 | # Non transpiled source code 20 | /src 21 | 22 | # Tests 23 | /test 24 | /.nyc_output 25 | /coverage 26 | 27 | # GitHub 28 | /.github 29 | 30 | # OSX 31 | .DS_Store 32 | 33 | # IDE 34 | .idea -------------------------------------------------------------------------------- /.prettierrc.yml: -------------------------------------------------------------------------------- 1 | printWidth: 100 2 | semi: false 3 | tabWidth: 4 4 | singleQuote: true 5 | bracketSpacing: true 6 | trailingComma: es5 7 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - '8' 4 | - '10' 5 | script: 6 | - yarn run lint 7 | - yarn run fmt:check 8 | - yarn run test:cover 9 | after_success: 10 | - yarn run coverage 11 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # mozaik-ext-github Changelog 2 | 3 | > **Tags:** 4 | > - [New Feature] 5 | > - [Bug Fix] 6 | > - [Breaking Change] 7 | > - [Documentation] 8 | > - [Internal] 9 | > - [Polish] 10 | 11 | 12 | ## v1.3.0 (2016-04-15) 13 | 14 | * **New Feature** 15 | * `widgets`: [#14](https://github.com/plouc/mozaik-ext-github/pull/14) Add ability to click on widgets github entities. 16 | 17 | 18 | ## v1.2.2 (2016-04-13) 19 | 20 | * **Polish** 21 | * `upgrade`: [40d0ea0](https://github.com/plouc/mozaik-ext-github/commit/40d0ea0b2ef88ada5eac1d5315e8a79361472e8d) Upgrade outdated packages. 22 | 23 | 24 | ## v1.2.1 (2016-04-06) 25 | 26 | * **Bug Fix** 27 | * `status`: [d845447](https://github.com/plouc/mozaik-ext-github/commit/d845447603de63c3ce9fc22ac77fd3e614ee3519) Fix status widget title. 28 | 29 | 30 | ## v1.2.0 (2016-04-04) 31 | 32 | * **Internal** 33 | * `mozaik`: [#11](https://github.com/plouc/mozaik-ext-github/pull/11) Make extension compatible with `mozaik@1.1.0`. 34 | * `babel`: [#11](https://github.com/plouc/mozaik-ext-github/pull/11) Update babel packages. 35 | * `test-runner`: [#11](https://github.com/plouc/mozaik-ext-github/pull/11) Move tests to **ava**. 36 | * `code-coverage`: [#11](https://github.com/plouc/mozaik-ext-github/pull/11) Generate code coverage through **nyc**. 37 | 38 | 39 | ## v1.1.0 (2016-04-02) 40 | 41 | * **New Feature** 42 | * `pull-requests`: [#10](https://github.com/plouc/mozaik-ext-github/pull/10) Provide optional PullRequests title. 43 | * `organization-badge`: [#6](https://github.com/plouc/mozaik-ext-github/pull/6) Add OrganizationBadge widget based on UserBadge. 44 | 45 | * **Bug Fix** 46 | * `pull-requests-gauge`: [#4](https://github.com/plouc/mozaik-ext-github/pull/4) Fix PullRequestsGauge widget. 47 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015-2016 Raphaël Benitte 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of 4 | this software and associated documentation files (the "Software"), to deal in 5 | the Software without restriction, including without limitation the rights to 6 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 7 | of the Software, and to permit persons to whom the Software is furnished to do 8 | so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Mozaïk GitHub widgets 2 | 3 | [![License][license-image]][license-url] 4 | [![Travis CI][travis-image]][travis-url] 5 | [![NPM version][npm-image]][npm-url] 6 | [![Dependencies][gemnasium-image]][gemnasium-url] 7 | [![Coverage Status][coverage-image]][coverage-url] 8 | ![widget count][widget-count-image] 9 | 10 | [![Deploy][heroku-image]][heroku-url] 11 | 12 | > This branch contains code for the version compatible with 13 | > Mozaïk v2, if you're looking for v1, please use 14 | > [mozaik-1 branch](https://github.com/plouc/mozaik-ext-github/tree/mozaik-1). 15 | 16 | This repository contains some GitHub widgets to use with [Mozaïk](https://github.com/plouc/mozaik). 17 | 18 | ## Demo 19 | 20 | You can see a live demo of the widgets [here](http://mozaik-ext-github-v2.herokuapp.com/) 21 | 22 | ## Widgets 23 | 24 | - [Badges](#badges) 25 | - [``](#orgbadge) 26 | - [``](#repobadge) 27 | - [``](#userbadge) 28 | - [Stats](#stats) 29 | - [``](#repocommitactivityhistogram) 30 | - [``](#repocommitactivityline) 31 | - [``](#repocontributorsstats) 32 | - [Traffic](#traffic) 33 | - [``](#repotrafficcloneshistogram) 34 | - [``](#repotrafficclonesline) 35 | - [``](#repotrafficviewshistogram) 36 | - [``](#repotrafficviewsline) 37 | - [``](#branches) 38 | - [``](#pullrequests) 39 | - [``](#status) 40 | 41 | 42 | ## Github Client Configuration 43 | 44 | In order to use the Mozaïk github widgets, you should configure its **client**. 45 | It's not required that you provide a token for authentication, but then 46 | you'll only be able to see public repos and the rate limit will apply. 47 | 48 | ### parameters 49 | 50 | key | env key | required | default | description 51 | ----------|------------------|----------|------------------------|---------------------------- 52 | `token` | GITHUB_API_TOKEN | no | '' | *github authentication token* 53 | `baseUrl` | GITHUB_BASE_URL | no | https://api.github.com | *github api url* (useful for enterprise) 54 | 55 | ### usage 56 | 57 | ``` yaml 58 | # config.yml 59 | api: 60 | github: 61 | baseUrl: "" 62 | token: MY_GITHUB_TOKEN 63 | ``` 64 | 65 | ## Widgets doc 66 | 67 | ### Badges 68 | 69 | #### OrgBadge 70 | 71 | > Show github organization badge. 72 | 73 | ![github organization badge](https://raw.githubusercontent.com/plouc/mozaik-ext-github/master/preview/github.organization_badge.png) 74 | 75 | ##### parameters 76 | 77 | key | required | description 78 | --------|----------|-------------------------- 79 | `org` | yes | *github organization identifier* 80 | `title` | no | *overrides default title if provided* 81 | 82 | ##### usage 83 | 84 | ``` yaml 85 | # config.yml 86 | dashboards: 87 | - # … 88 | widgets: 89 | - extension: github 90 | widget: OrgBadge 91 | organization: github 92 | columns: 1 93 | rows: 1 94 | x: 0 95 | y: 0 96 | ``` 97 | 98 | 99 | #### RepoBadge 100 | 101 | > Show repository info. 102 | 103 | ##### parameters 104 | 105 | key | required | description 106 | -------------|----------|--------------- 107 | `repository` | yes | *github repository* 108 | `title` | no | *overrides default title if provided* 109 | 110 | ##### usage 111 | 112 | ``` yaml 113 | # config.yml 114 | dashboards: 115 | - # … 116 | widgets: 117 | - extension: github 118 | widget: RepoBadge 119 | repository: plouc/mozaik 120 | columns: 1 121 | rows: 1 122 | x: 0 123 | y: 0 124 | ``` 125 | 126 | 127 | #### UserBadge 128 | 129 | > Show github user badge. 130 | 131 | ![github user badge](https://raw.githubusercontent.com/plouc/mozaik-ext-github/master/preview/github.user_badge.png) 132 | 133 | ##### parameters 134 | 135 | key | required | description 136 | --------|----------|-------------------------- 137 | `user` | yes | *github user identifier* 138 | `title` | no | *overrides default title if provided* 139 | 140 | ##### usage 141 | 142 | ``` yaml 143 | # config.yml 144 | dashboards: 145 | - # … 146 | widgets: 147 | - extension: github 148 | widget: UserBadge 149 | user: plouc 150 | columns: 1 151 | rows: 1 152 | x: 0 153 | y: 0 154 | ``` 155 | 156 | 157 | ### Stats 158 | 159 | #### RepoCommitActivityHistogram 160 | 161 | ##### parameters 162 | 163 | key | required | description 164 | -------------|----------|--------------- 165 | `repository` | yes | *github repository* 166 | `title` | no | *overrides default title if provided* 167 | 168 | ##### usage 169 | 170 | ``` yaml 171 | # config.yml 172 | dashboards: 173 | - # … 174 | widgets: 175 | - extension: github 176 | widget: RepoCommitActivityHistogram 177 | repository: plouc/mozaik 178 | columns: 2 179 | rows: 1 180 | x: 0 181 | y: 0 182 | ``` 183 | 184 | 185 | #### RepoCommitActivityLine 186 | 187 | ##### parameters 188 | 189 | key | required | description 190 | -------------|----------|--------------- 191 | `repository` | yes | *github repository* 192 | `title` | no | *overrides default title if provided* 193 | 194 | ##### usage 195 | 196 | ``` yaml 197 | # config.yml 198 | dashboards: 199 | - # … 200 | widgets: 201 | - extension: github 202 | widget: RepoCommitActivityLine 203 | repository: plouc/mozaik 204 | columns: 2 205 | rows: 1 206 | x: 0 207 | y: 0 208 | ``` 209 | 210 | 211 | #### RepoContributorsStats 212 | 213 | ##### parameters 214 | 215 | key | required | description 216 | -------------|----------|--------------- 217 | `repository` | yes | *github repository* 218 | `title` | no | *overrides default title if provided* 219 | 220 | ##### usage 221 | 222 | ``` yaml 223 | # config.yml 224 | dashboards: 225 | - # … 226 | widgets: 227 | - extension: github 228 | widget: RepoContributorsStats 229 | repository: plouc/mozaik 230 | columns: 2 231 | rows: 1 232 | x: 0 233 | y: 0 234 | ``` 235 | 236 | 237 | ### Traffic 238 | 239 | #### RepoTrafficClonesHistogram 240 | 241 | ##### parameters 242 | 243 | key | required | description 244 | -------------|----------|--------------- 245 | `repository` | yes | *github repository* 246 | `title` | no | *overrides default title if provided* 247 | 248 | ##### usage 249 | 250 | ``` yaml 251 | # config.yml 252 | dashboards: 253 | - # … 254 | widgets: 255 | - extension: github 256 | widget: RepoTrafficClonesHistogram 257 | repository: plouc/mozaik 258 | columns: 2 259 | rows: 1 260 | x: 0 261 | y: 0 262 | ``` 263 | 264 | 265 | #### RepoTrafficClonesLine 266 | 267 | ##### parameters 268 | 269 | key | required | description 270 | -------------|----------|--------------- 271 | `repository` | yes | *github repository* 272 | `title` | no | *overrides default title if provided* 273 | 274 | ##### usage 275 | 276 | ``` yaml 277 | # config.yml 278 | dashboards: 279 | - # … 280 | widgets: 281 | - extension: github 282 | widget: RepoTrafficClonesLine 283 | repository: plouc/mozaik 284 | columns: 2 285 | rows: 1 286 | x: 0 287 | y: 0 288 | ``` 289 | 290 | 291 | #### RepoTrafficViewsHistogram 292 | 293 | ##### parameters 294 | 295 | key | required | description 296 | -------------|----------|--------------- 297 | `repository` | yes | *github repository* 298 | `title` | no | *overrides default title if provided* 299 | 300 | ##### usage 301 | 302 | ``` yaml 303 | # config.yml 304 | dashboards: 305 | - # … 306 | widgets: 307 | - extension: github 308 | widget: RepoTrafficViewsHistogram 309 | repository: plouc/mozaik 310 | columns: 2 311 | rows: 1 312 | x: 0 313 | y: 0 314 | ``` 315 | 316 | 317 | #### RepoTrafficViewsLine 318 | 319 | ##### parameters 320 | 321 | key | required | description 322 | -------------|----------|--------------- 323 | `repository` | yes | *github repository* 324 | `title` | no | *overrides default title if provided* 325 | 326 | ##### usage 327 | 328 | ``` yaml 329 | # config.yml 330 | dashboards: 331 | - # … 332 | widgets: 333 | - extension: github 334 | widget: RepoTrafficViewsLine 335 | repository: plouc/mozaik 336 | columns: 2 337 | rows: 1 338 | x: 0 339 | y: 0 340 | ``` 341 | 342 | 343 | ### Branches 344 | 345 | > Show github branches with authors. 346 | 347 | ![github repository branches](https://raw.githubusercontent.com/plouc/mozaik-ext-github/master/preview/github.branches.png) 348 | 349 | #### parameters 350 | 351 | key | required | description 352 | -------------|----------|--------------- 353 | `repository` | yes | *github repository* 354 | `title` | no | *overrides default title if provided* 355 | 356 | #### usage 357 | 358 | ``` yaml 359 | # config.yml 360 | dashboards: 361 | - # … 362 | widgets: 363 | - extension: github 364 | widget: Branches 365 | repository: plouc/mozaik 366 | columns: 1 367 | rows: 1 368 | x: 0 369 | y: 0 370 | ``` 371 | 372 | 373 | ### PullRequests 374 | 375 | > Show github repository pull requests with authors. 376 | 377 | #### parameters 378 | 379 | key | required | description 380 | -------------|----------|--------------- 381 | `repository` | yes | *github repository* 382 | `title` | no | *overrides default title if provided* 383 | 384 | #### usage 385 | 386 | ``` yaml 387 | # config.yml 388 | dashboards: 389 | - # … 390 | widgets: 391 | - extension: github 392 | widget: PullRequests 393 | repository: plouc/mozaik 394 | columns: 1 395 | rows: 1 396 | x: 0 397 | y: 0 398 | ``` 399 | 400 | 401 | ### Status 402 | 403 | > Shows the latest Github system status information from [https://status.github.com/](https://status.github.com/) 404 | 405 | ![Github Status](https://raw.githubusercontent.com/plouc/mozaik-ext-github/master/preview/github.status.png) 406 | 407 | #### usage 408 | 409 | ``` yaml 410 | # config.yml 411 | dashboards: 412 | - # … 413 | widgets: 414 | - extension: github 415 | widget: Status 416 | columns: 1 417 | rows: 1 418 | x: 0 419 | y: 0 420 | ``` 421 | 422 | 423 | [license-image]: https://img.shields.io/github/license/plouc/mozaik-ext-github.svg?style=flat-square 424 | [license-url]: https://github.com/plouc/mozaik-ext-github/blob/master/LICENSE.md 425 | [travis-image]: https://img.shields.io/travis/plouc/mozaik-ext-github.svg?style=flat-square 426 | [travis-url]: https://travis-ci.org/plouc/mozaik-ext-github 427 | [npm-image]: https://img.shields.io/npm/v/mozaik-ext-github.svg?style=flat-square 428 | [npm-url]: https://www.npmjs.com/package/mozaik-ext-github 429 | [gemnasium-image]: https://img.shields.io/gemnasium/plouc/mozaik-ext-github.svg?style=flat-square 430 | [gemnasium-url]: https://gemnasium.com/plouc/mozaik-ext-github 431 | [coverage-image]: https://img.shields.io/coveralls/plouc/mozaik-ext-github.svg?style=flat-square 432 | [coverage-url]: https://coveralls.io/github/plouc/mozaik-ext-github 433 | [widget-count-image]: https://img.shields.io/badge/widgets-x13-green.svg?style=flat-square 434 | [heroku-image]: https://www.herokucdn.com/deploy/button.svg 435 | [heroku-url]: https://heroku.com/deploy?template=https://github.com/plouc/mozaik-ext-github/tree/demo -------------------------------------------------------------------------------- /client.js: -------------------------------------------------------------------------------- 1 | module.exports = require('./lib/client') 2 | -------------------------------------------------------------------------------- /commitlint.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | extends: ['@commitlint/config-conventional'], 3 | } 4 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@mozaik/ext-github", 3 | "version": "2.0.0-alpha.10", 4 | "description": "Mozaik github widgets", 5 | "repository": { 6 | "type": "git", 7 | "url": "git://github.com/plouc/mozaik-ext-github" 8 | }, 9 | "license": "MIT", 10 | "author": { 11 | "name": "Raphaël Benitte", 12 | "url": "https://github.com/plouc" 13 | }, 14 | "homepage": "https://github.com/plouc/mozaik-ext-github", 15 | "main": "./lib/components/index.js", 16 | "module": "es/components/index.js", 17 | "jsnext:main": "es/components/index.js", 18 | "keywords": [ 19 | "github", 20 | "mozaik", 21 | "widget", 22 | "extension", 23 | "dashboard" 24 | ], 25 | "engineStrict": true, 26 | "engines": { 27 | "node": ">=8.3.0", 28 | "npm": ">=3.0.0" 29 | }, 30 | "dependencies": { 31 | "chalk": "^2.1.0", 32 | "convict": "^4.0.0", 33 | "moment": "^2.18.1", 34 | "moment-duration-format": "1.3.0", 35 | "prop-types": "^15.5.10" 36 | }, 37 | "devDependencies": { 38 | "@commitlint/cli": "^7.0.0", 39 | "@commitlint/config-conventional": "^7.0.1", 40 | "@mozaik/babel-preset": "^1.0.0-alpha.6", 41 | "@mozaik/ui": "^2.0.0-rc.0", 42 | "babel-cli": "^6.26.0", 43 | "babel-eslint": "^7.2.3", 44 | "babel-jest": "^20.0.3", 45 | "coveralls": "^2.13.1", 46 | "cross-env": "^5.0.5", 47 | "enzyme": "^3.3.0", 48 | "enzyme-adapter-react-16": "^1.1.1", 49 | "eslint": "^5.2.0", 50 | "eslint-plugin-react": "^7.10.0", 51 | "husky": "^0.14.3", 52 | "jest": "^23.4.2", 53 | "lint-staged": "^7.2.0", 54 | "nivo": "^0.15.0", 55 | "nock": "^9.0.14", 56 | "prettier": "^1.14.0", 57 | "react": "^16.4.0", 58 | "react-dom": "^16.4.0", 59 | "react-test-renderer": "^16.4.0", 60 | "styled-components": "^2.1.2" 61 | }, 62 | "peerDependencies": { 63 | "@mozaik/ui": "^2.0.0-rc.0", 64 | "nivo": "^0.15.0", 65 | "react": "^16.4.0" 66 | }, 67 | "scripts": { 68 | "lint": "eslint ./src/** ./test/**", 69 | "lint:fix": "eslint --fix ./src/** ./test/**", 70 | "test": "jest --verbose", 71 | "test:cover": "jest --verbose --coverage", 72 | "coverage": "cat ./coverage/lcov.info | coveralls", 73 | "build:commonjs": "cross-env BABEL_ENV=commonjs babel src --out-dir lib", 74 | "build:commonjs:watch": "npm run build:commonjs -- --watch", 75 | "build:es": "cross-env BABEL_ENV=es babel src --out-dir es", 76 | "build:es:watch": "npm run build:es -- --watch", 77 | "build": "npm run build:commonjs && npm run build:es", 78 | "fmt": "prettier --print-width=100 --tab-width=4 --bracket-spacing --no-semi --trailing-comma es5 --single-quote --color --write \"{src,test}/**/*.js\" 'client.js'", 79 | "fmt:check": "prettier --print-width=100 --tab-width=4 --bracket-spacing --no-semi --trailing-comma es5 --single-quote --list-different \"{src,test}/**/*.js\" 'client.js'", 80 | "prepublishOnly": "npm run lint && npm test && npm run build", 81 | "version": "echo ${npm_package_version}", 82 | "precommit": "lint-staged", 83 | "commitmsg": "commitlint -E GIT_PARAMS" 84 | }, 85 | "jest": { 86 | "setupTestFrameworkScriptFile": "test/setupTests.js", 87 | "testURL": "http://localhost/" 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /preview/github.branches.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plouc/mozaik-ext-github/25cdba78e1bf980e1784f2410e615f43fe703bba/preview/github.branches.png -------------------------------------------------------------------------------- /preview/github.issue_labels_donut.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plouc/mozaik-ext-github/25cdba78e1bf980e1784f2410e615f43fe703bba/preview/github.issue_labels_donut.png -------------------------------------------------------------------------------- /preview/github.issue_types_treemap.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plouc/mozaik-ext-github/25cdba78e1bf980e1784f2410e615f43fe703bba/preview/github.issue_types_treemap.png -------------------------------------------------------------------------------- /preview/github.organization_badge.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plouc/mozaik-ext-github/25cdba78e1bf980e1784f2410e615f43fe703bba/preview/github.organization_badge.png -------------------------------------------------------------------------------- /preview/github.repository_contributors_stats.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plouc/mozaik-ext-github/25cdba78e1bf980e1784f2410e615f43fe703bba/preview/github.repository_contributors_stats.png -------------------------------------------------------------------------------- /preview/github.status.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plouc/mozaik-ext-github/25cdba78e1bf980e1784f2410e615f43fe703bba/preview/github.status.png -------------------------------------------------------------------------------- /preview/github.user_badge.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/plouc/mozaik-ext-github/25cdba78e1bf980e1784f2410e615f43fe703bba/preview/github.user_badge.png -------------------------------------------------------------------------------- /src/client.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | const chalk = require('chalk') 4 | const config = require('./config') 5 | 6 | // https://developer.github.com/v3/#user-agent-required 7 | const userAgent = '@mozaik/ext-github' 8 | const previewAcceptHeader = 'application/vnd.github.spiderman-preview' 9 | 10 | /** 11 | * @param {Mozaik} mozaik 12 | */ 13 | const client = mozaik => { 14 | mozaik.loadApiConfig(config) 15 | 16 | const buildApiRequest = (path, params) => { 17 | const url = config.get('github.baseUrl') 18 | 19 | const options = { 20 | uri: `${url}${path}`, 21 | qs: {}, 22 | json: true, 23 | resolveWithFullResponse: true, 24 | headers: { 25 | 'User-Agent': userAgent, 26 | Accept: previewAcceptHeader, 27 | }, 28 | } 29 | 30 | const paramsDebug = params ? ` ${JSON.stringify(params)}` : '' 31 | mozaik.logger.info(chalk.yellow(`[github] calling ${url}${path}${paramsDebug}`)) 32 | 33 | if (params) { 34 | options.qs = params 35 | } 36 | 37 | if (config.get('github.token') !== '') { 38 | options.headers.Authorization = `token ${config.get('github.token')}` 39 | } 40 | 41 | return mozaik.request(options) 42 | } 43 | 44 | const repositoryCommits = (params, buffer) => { 45 | return buildApiRequest(`/repos/${params.repository}/commits`, params).then(res => { 46 | buffer.commits = buffer.commits.concat(res.body) 47 | 48 | // checks if there's an available next page in response link http header 49 | if ( 50 | res.headers.link && 51 | /&page=(\d+)> rel="next"/.test(res.headers.link) === true && 52 | buffer.commits.length < buffer.max 53 | ) { 54 | buffer.page = Number(/&page=(\d+)> rel="next"/.exec(res.headers.link)[1]) 55 | 56 | return repositoryCommits(params, buffer) 57 | } else { 58 | return buffer.commits 59 | } 60 | }) 61 | } 62 | 63 | const apiCalls = { 64 | organization({ organization }) { 65 | return buildApiRequest(`/orgs/${organization}`).then(res => res.body) 66 | }, 67 | 68 | user({ user }) { 69 | return buildApiRequest(`/users/${user}`).then(({ body }) => body) 70 | }, 71 | 72 | repository({ repository }) { 73 | return buildApiRequest(`/repos/${repository}`).then(({ body }) => body) 74 | }, 75 | 76 | pullRequests({ repository }) { 77 | return buildApiRequest(`/repos/${repository}/pulls`).then(({ body: pullRequests }) => ({ 78 | pullRequests, 79 | })) 80 | }, 81 | 82 | repositoryParticipationStats({ repository }) { 83 | return buildApiRequest(`/repos/${repository}/stats/participation`).then( 84 | ({ body }) => body 85 | ) 86 | }, 87 | 88 | repositoryLanguages({ repository }) { 89 | return buildApiRequest(`/repos/${repository}/languages`).then(({ body }) => body) 90 | }, 91 | 92 | // Be warned that this API call can be heavy enough 93 | // because it loads each branch details with an extra call 94 | branches(params) { 95 | return buildApiRequest(`/repos/${params.repository}/branches`) 96 | .then(res => { 97 | return Promise.all( 98 | res.body.map(branch => { 99 | return apiCalls.branch(Object.assign({ branch: branch.name }, params)) 100 | }) 101 | ) 102 | }) 103 | .then(branches => ({ branches })) 104 | }, 105 | 106 | branch({ repository, branch }) { 107 | return buildApiRequest(`/repos/${repository}/branches/${branch}`).then( 108 | ({ body }) => body 109 | ) 110 | }, 111 | 112 | repositoryContributorsStats({ repository }) { 113 | return buildApiRequest(`/repos/${repository}/stats/contributors`).then(res => ({ 114 | contributors: res.body, 115 | })) 116 | }, 117 | 118 | repoCommitActivity({ repository }) { 119 | return buildApiRequest(`/repos/${repository}/stats/commit_activity`).then(res => ({ 120 | buckets: res.body, 121 | })) 122 | }, 123 | 124 | repositoryCommits(params) { 125 | return repositoryCommits(params, { 126 | commits: [], 127 | page: 1, 128 | max: 1000, 129 | }) 130 | }, 131 | 132 | issues({ repository }) { 133 | return buildApiRequest(`/repos/${repository}/issues`).then(({ body }) => body) 134 | }, 135 | 136 | // Be warned that this API call can be heavy enough 137 | // because it fetch all the issues for each labels 138 | issueLabelsAggregations(params) { 139 | params.labels.forEach(label => { 140 | label.count = 0 141 | }) 142 | 143 | return Promise.all( 144 | params.labels.map(label => { 145 | return buildApiRequest(`/repos/${params.repository}/issues`, { 146 | labels: label.name, 147 | state: 'open', 148 | filter: 'all', 149 | }).then(res => { 150 | label.count = res.body.length 151 | 152 | return label 153 | }) 154 | }) 155 | ) 156 | }, 157 | 158 | status() { 159 | const url = 'https://status.github.com/api/last-message.json' 160 | let req = mozaik.request.get(url) 161 | 162 | mozaik.logger.info(chalk.yellow(`[github] calling ${url}`)) 163 | 164 | return req.promise().then(res => res.body) 165 | }, 166 | 167 | trafficViews({ repository }) { 168 | return buildApiRequest(`/repos/${repository}/traffic/views`).then(({ body }) => body) 169 | }, 170 | 171 | trafficClones({ repository }) { 172 | return buildApiRequest(`/repos/${repository}/traffic/clones`).then(({ body }) => body) 173 | }, 174 | } 175 | 176 | return apiCalls 177 | } 178 | 179 | module.exports = client 180 | -------------------------------------------------------------------------------- /src/components/Branch.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react' 2 | import PropTypes from 'prop-types' 3 | import { WidgetListItem, WidgetAvatar, ExternalLink } from '@mozaik/ui' 4 | 5 | export const BranchPropType = PropTypes.shape({ 6 | name: PropTypes.string.isRequired, 7 | _links: PropTypes.shape({ 8 | html: PropTypes.string.isRequired, 9 | }).isRequired, 10 | commit: PropTypes.shape({ 11 | author: PropTypes.shape({ 12 | login: PropTypes.string.isRequired, 13 | avatar_url: PropTypes.string.isRequired, 14 | html_url: PropTypes.string.isRequired, 15 | }), 16 | }), 17 | }) 18 | 19 | export default class Branch extends Component { 20 | static propTypes = { 21 | branch: BranchPropType.isRequired, 22 | } 23 | 24 | render() { 25 | const { branch } = this.props 26 | const { commit } = branch 27 | 28 | return ( 29 | 32 | {branch.name} 33 |   34 | {commit && 35 | commit.author && ( 36 | 37 | by{' '} 38 | 39 | {commit.author.login} 40 | 41 | 42 | )} 43 | 44 | } 45 | post={ 46 | commit && 47 | commit.author && ( 48 | 49 | {commit.author.login} 50 | 51 | ) 52 | } 53 | /> 54 | ) 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/components/Branches.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react' 2 | import PropTypes from 'prop-types' 3 | import { 4 | TrapApiError, 5 | Widget, 6 | WidgetHeader, 7 | WidgetBody, 8 | WidgetLoader, 9 | GitBranchIcon, 10 | } from '@mozaik/ui' 11 | import Branch, { BranchPropType } from './Branch' 12 | 13 | export default class Branches extends Component { 14 | static propTypes = { 15 | repository: PropTypes.string.isRequired, 16 | title: PropTypes.string, 17 | apiData: PropTypes.shape({ 18 | branches: PropTypes.arrayOf(BranchPropType).isRequired, 19 | }), 20 | apiError: PropTypes.object, 21 | } 22 | 23 | static getApiRequest({ repository }) { 24 | return { 25 | id: `github.branches.${repository}`, 26 | params: { repository }, 27 | } 28 | } 29 | 30 | render() { 31 | const { repository, title, apiData, apiError } = this.props 32 | 33 | let body = 34 | let count 35 | if (apiData && !apiError) { 36 | count = apiData.branches.length 37 | body = ( 38 |
39 | {apiData.branches.map(branch => ( 40 | 41 | ))} 42 |
43 | ) 44 | } 45 | 46 | return ( 47 | 48 | 54 | 55 | {body} 56 | 57 | 58 | ) 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/components/Status.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react' 2 | import PropTypes from 'prop-types' 3 | import moment from 'moment' 4 | import { 5 | TrapApiError, 6 | Widget, 7 | WidgetHeader, 8 | WidgetBody, 9 | WidgetStatusBadge, 10 | ClockIcon, 11 | GithubIcon, 12 | } from '@mozaik/ui' 13 | 14 | export default class Status extends Component { 15 | static propTypes = { 16 | apiData: PropTypes.shape({ 17 | status: PropTypes.string.isRequired, 18 | body: PropTypes.string.isRequired, 19 | }), 20 | apiError: PropTypes.object, 21 | } 22 | 23 | static getApiRequest() { 24 | return { id: 'github.status' } 25 | } 26 | 27 | render() { 28 | const { apiData: _status, apiError } = this.props 29 | 30 | let status = 'unknown' 31 | let messageNode 32 | let meta 33 | if (_status) { 34 | status = _status.status 35 | messageNode = _status.body 36 | meta = ( 37 | 38 | 39 |   40 | {moment(_status.created_on).fromNow()} 41 | 42 | ) 43 | } 44 | 45 | return ( 46 | 47 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | ) 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/components/badges/OrgBadge.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react' 2 | import PropTypes from 'prop-types' 3 | import { 4 | TrapApiError, 5 | Widget, 6 | WidgetLabel, 7 | WidgetHeader, 8 | WidgetBody, 9 | WidgetLoader, 10 | WidgetAvatar, 11 | ExternalLink, 12 | GithubIcon, 13 | } from '@mozaik/ui' 14 | 15 | export default class OrgBadge extends Component { 16 | static propTypes = { 17 | organization: PropTypes.string.isRequired, 18 | title: PropTypes.string, 19 | apiData: PropTypes.shape({}), 20 | apiError: PropTypes.object, 21 | } 22 | 23 | static getApiRequest({ organization }) { 24 | return { 25 | id: `github.organization.${organization}`, 26 | params: { organization }, 27 | } 28 | } 29 | 30 | render() { 31 | const { organization, title, apiData: orgInfo, apiError } = this.props 32 | 33 | let body = 34 | if (orgInfo) { 35 | body = ( 36 |
47 |
55 | 56 | 57 | {this.props.organization} 58 | 59 | 60 |
61 |
67 | {orgInfo.description} 68 |
69 |
76 | 79 | public repos 80 | 81 | } 82 | prefix={orgInfo.public_repos} 83 | style={{ width: '48%', marginBottom: '1vmin' }} 84 | /> 85 | 90 | 95 | 100 |
101 |
102 | ) 103 | } 104 | 105 | return ( 106 | 107 | 112 | 113 | {body} 114 | 115 | 116 | ) 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /src/components/badges/RepoBadge.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react' 2 | import PropTypes from 'prop-types' 3 | import { 4 | TrapApiError, 5 | Widget, 6 | WidgetHeader, 7 | WidgetBody, 8 | WidgetLoader, 9 | WidgetLabel as Label, 10 | ExternalLink, 11 | GithubIcon, 12 | } from '@mozaik/ui' 13 | 14 | export default class RepoBadge extends Component { 15 | static propTypes = { 16 | repository: PropTypes.string.isRequired, 17 | title: PropTypes.string, 18 | apiData: PropTypes.object, 19 | apiError: PropTypes.object, 20 | showKeys: PropTypes.arrayOf(PropTypes.string).isRequired, 21 | } 22 | 23 | static defaultProps = { 24 | showKeys: ['description'], 25 | } 26 | 27 | static getApiRequest({ repository }) { 28 | return { 29 | id: `github.repository.${repository}`, 30 | params: { repository }, 31 | } 32 | } 33 | 34 | render() { 35 | const { repository, title, apiData: repoInfo, apiError } = this.props 36 | 37 | let body = 38 | if (repoInfo) { 39 | const labelStyle = { width: '48%', marginBottom: '1vmin' } 40 | 41 | body = ( 42 |
51 |
57 | {repoInfo.description} 58 |
59 |
66 |
103 |
104 | ) 105 | } 106 | 107 | return ( 108 | 109 | 114 | 115 | {body} 116 | 117 | 118 | ) 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /src/components/badges/UserBadge.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react' 2 | import PropTypes from 'prop-types' 3 | import { 4 | TrapApiError, 5 | Widget, 6 | WidgetHeader, 7 | WidgetBody, 8 | WidgetLoader, 9 | WidgetLabel, 10 | WidgetAvatar, 11 | ExternalLink, 12 | GithubIcon, 13 | } from '@mozaik/ui' 14 | 15 | export default class UserBadge extends Component { 16 | static propTypes = { 17 | user: PropTypes.string.isRequired, 18 | title: PropTypes.string, 19 | apiData: PropTypes.shape({}), 20 | apiError: PropTypes.object, 21 | } 22 | 23 | static getApiRequest({ user }) { 24 | return { 25 | id: `github.user.${user}`, 26 | params: { user }, 27 | } 28 | } 29 | 30 | render() { 31 | const { title, apiData: user, apiError } = this.props 32 | 33 | let body = 34 | if (user) { 35 | body = ( 36 |
46 |
54 | 55 | 56 | {this.props.user} 57 | 58 | 59 |
60 |
67 | 70 | public repos 71 | 72 | } 73 | prefix={user.public_repos} 74 | style={{ width: '48%', marginBottom: '1vmin' }} 75 | /> 76 | 81 | 84 | followers 85 | 86 | } 87 | prefix={user.followers} 88 | style={{ width: '48%', marginBottom: '1vmin' }} 89 | /> 90 | 93 | following 94 | 95 | } 96 | prefix={user.following} 97 | style={{ width: '48%', marginBottom: '1vmin' }} 98 | /> 99 | 104 |
105 |
106 | ) 107 | } 108 | 109 | return ( 110 | 111 | 116 | 117 | {body} 118 | 119 | 120 | ) 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /src/components/index.js: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the Mozaïk project. 3 | * 4 | * (c) 2016 Raphaël Benitte 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | */ 9 | 10 | import Branches from './Branches' 11 | import PullRequests from './pull-requests/PullRequests' 12 | import UserBadge from './badges/UserBadge' 13 | import OrgBadge from './badges/OrgBadge' 14 | import RepoBadge from './badges/RepoBadge' 15 | import RepoContributorsStats from './stats/RepoContributorsStats' 16 | import Status from './Status' 17 | import RepoTrafficViewsHistogram from './traffic/RepoTrafficViewsHistogram' 18 | import RepoTrafficViewsLine from './traffic/RepoTrafficViewsLine' 19 | import RepoTrafficClonesHistogram from './traffic/RepoTrafficClonesHistogram' 20 | import RepoTrafficClonesLine from './traffic/RepoTrafficClonesLine' 21 | import RepoCommitActivityHistogram from './stats/RepoCommitActivityHistogram' 22 | import RepoCommitActivityLine from './stats/RepoCommitActivityLine' 23 | 24 | export default { 25 | Branches, 26 | PullRequests, 27 | UserBadge, 28 | OrgBadge, 29 | RepoBadge, 30 | RepoContributorsStats, 31 | Status, 32 | RepoTrafficViewsHistogram, 33 | RepoTrafficViewsLine, 34 | RepoTrafficClonesHistogram, 35 | RepoTrafficClonesLine, 36 | RepoCommitActivityHistogram, 37 | RepoCommitActivityLine, 38 | } 39 | -------------------------------------------------------------------------------- /src/components/pull-requests/PullRequest.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react' 2 | import PropTypes from 'prop-types' 3 | import moment from 'moment' 4 | import { WidgetListItem, WidgetAvatar, ExternalLink, ClockIcon } from '@mozaik/ui' 5 | 6 | export default class PullRequest extends Component { 7 | static propTypes = { 8 | pullRequest: PropTypes.shape({ 9 | title: PropTypes.string.isRequired, 10 | html_url: PropTypes.string.isRequired, 11 | created_at: PropTypes.string.isRequired, 12 | user: PropTypes.shape({ 13 | html_url: PropTypes.string.isRequired, 14 | avatar_url: PropTypes.string.isRequired, 15 | login: PropTypes.string.isRequired, 16 | }).isRequired, 17 | }).isRequired, 18 | } 19 | 20 | render() { 21 | const { pullRequest } = this.props 22 | const { title, html_url, created_at, user } = pullRequest 23 | 24 | return ( 25 | 28 | {title} by{' '} 29 | {user.login} 30 | 31 | } 32 | pre={ 33 | 34 | {user.login} 35 | 36 | } 37 | meta={ 38 | 44 | 45 |   46 | {moment(created_at).fromNow()} 47 | 48 | } 49 | align="top" 50 | /> 51 | ) 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/components/pull-requests/PullRequests.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react' 2 | import PropTypes from 'prop-types' 3 | import { 4 | TrapApiError, 5 | Widget, 6 | WidgetHeader, 7 | WidgetBody, 8 | WidgetLoader, 9 | GithubIcon, 10 | } from '@mozaik/ui' 11 | import PullRequest from './PullRequest' 12 | 13 | export default class PullRequests extends Component { 14 | static propTypes = { 15 | repository: PropTypes.string.isRequired, 16 | title: PropTypes.string, 17 | apiData: PropTypes.shape({ 18 | pullRequests: PropTypes.arrayOf(PropTypes.object).isRequired, 19 | }), 20 | apiError: PropTypes.object, 21 | } 22 | 23 | static getApiRequest({ repository }) { 24 | return { 25 | id: `github.pullRequests.${repository}`, 26 | params: { repository }, 27 | } 28 | } 29 | 30 | render() { 31 | const { repository, title, apiData, apiError } = this.props 32 | 33 | let body = 34 | let count = 0 35 | if (apiData) { 36 | count = apiData.pullRequests.length 37 | body = ( 38 |
39 | {apiData.pullRequests.map(pullRequest => ( 40 | 41 | ))} 42 |
43 | ) 44 | } 45 | 46 | return ( 47 | 48 | 54 | 55 | {body} 56 | 57 | 58 | ) 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/components/stats/RepoCommitActivity.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react' 2 | import PropTypes from 'prop-types' 3 | import RepoCommitActivityHistogramChart from './charts/RepoCommitActivityHistogramChart' 4 | import RepoCommitActivityLineChart from './charts/RepoCommitActivityLineChart' 5 | import { 6 | TrapApiError, 7 | Widget, 8 | WidgetHeader, 9 | WidgetBody, 10 | WidgetLoader, 11 | GithubIcon, 12 | } from '@mozaik/ui' 13 | 14 | export default class RepositoryCommitActivity extends Component { 15 | static propTypes = { 16 | repository: PropTypes.string.isRequired, 17 | title: PropTypes.string, 18 | apiData: PropTypes.shape({ 19 | buckets: PropTypes.arrayOf(PropTypes.object).isRequired, 20 | }), 21 | apiError: PropTypes.object, 22 | type: PropTypes.oneOf(['histogram', 'line']).isRequired, 23 | theme: PropTypes.object.isRequired, 24 | } 25 | 26 | static getApiRequest({ repository }) { 27 | return { 28 | id: `github.repoCommitActivity.${repository}`, 29 | params: { repository }, 30 | } 31 | } 32 | 33 | render() { 34 | const { repository, title, type, apiData, apiError, theme } = this.props 35 | 36 | let body = 37 | if (apiData && !apiError) { 38 | if (type === 'histogram') { 39 | body = 40 | } else if (type === 'line') { 41 | const chartData = [ 42 | { 43 | id: 'commits', 44 | data: apiData.buckets.map(datum => 45 | Object.assign({}, datum, { 46 | x: datum.week, 47 | y: datum.total, 48 | }) 49 | ), 50 | }, 51 | ] 52 | 53 | body = 54 | } 55 | } 56 | 57 | return ( 58 | 59 | 64 | 65 | {body} 66 | 67 | 68 | ) 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/components/stats/RepoCommitActivityHistogram.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react' 2 | import RepoCommitActivity from './RepoCommitActivity' 3 | 4 | export default class RepoCommitActivityHistogram extends Component { 5 | static getApiRequest(params) { 6 | return RepoCommitActivity.getApiRequest(params) 7 | } 8 | 9 | render() { 10 | return 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/components/stats/RepoCommitActivityLine.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react' 2 | import RepoCommitActivity from './RepoCommitActivity' 3 | 4 | export default class RepoCommitActivityLine extends Component { 5 | static getApiRequest(params) { 6 | return RepoCommitActivity.getApiRequest(params) 7 | } 8 | 9 | render() { 10 | return 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/components/stats/RepoContributorStat.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react' 2 | import PropTypes from 'prop-types' 3 | import { WidgetListItem, WidgetAvatar, ExternalLink, GitCommitIcon } from '@mozaik/ui' 4 | 5 | export default class RepoContributorStat extends Component { 6 | static propTypes = { 7 | contributor: PropTypes.shape({ 8 | total: PropTypes.number.isRequired, 9 | author: PropTypes.shape({ 10 | login: PropTypes.string.isRequired, 11 | avatar_url: PropTypes.string.isRequired, 12 | }).isRequired, 13 | }).isRequired, 14 | } 15 | 16 | render() { 17 | const { 18 | contributor: { author, total }, 19 | } = this.props 20 | 21 | return ( 22 | 25 | {author.login} 26 | 27 | } 28 | pre={ 29 | 30 | {author.login} 31 | 32 | } 33 | post={ 34 | 40 | {total} 41 |   42 | 43 | 44 | } 45 | /> 46 | ) 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/components/stats/RepoContributorsStats.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react' 2 | import PropTypes from 'prop-types' 3 | import { 4 | TrapApiError, 5 | Widget, 6 | WidgetHeader, 7 | WidgetBody, 8 | WidgetLoader, 9 | GithubIcon, 10 | } from '@mozaik/ui' 11 | import RepoContributorStat from './RepoContributorStat' 12 | 13 | export default class RepoContributorsStats extends Component { 14 | static propTypes = { 15 | repository: PropTypes.string.isRequired, 16 | title: PropTypes.string, 17 | apiData: PropTypes.shape({ 18 | contributors: PropTypes.arrayOf(PropTypes.object).isRequired, 19 | }), 20 | apiError: PropTypes.object, 21 | } 22 | 23 | static getApiRequest({ repository }) { 24 | return { 25 | id: `github.repositoryContributorsStats.${repository}`, 26 | params: { repository }, 27 | } 28 | } 29 | 30 | render() { 31 | const { repository, title, apiData, apiError } = this.props 32 | 33 | let body = 34 | let count 35 | if (apiData && !apiError) { 36 | const contributors = apiData.contributors 37 | .slice() 38 | .sort((contribA, contribB) => contribB.total - contribA.total) 39 | 40 | count = contributors.length 41 | body = ( 42 |
43 | {contributors.map(contributor => ( 44 | 48 | ))} 49 |
50 | ) 51 | } 52 | 53 | return ( 54 | 55 | 61 | 62 | {body} 63 | 64 | 65 | ) 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/components/stats/charts/RepoCommitActivityHistogramChart.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react' 2 | import PropTypes from 'prop-types' 3 | import moment from 'moment' 4 | import { ResponsiveBar } from 'nivo' 5 | 6 | const margin = { top: 10, right: 10, bottom: 54, left: 60 } 7 | const format = d => moment.unix(d).format('MM/DD') 8 | const axisLeft = { 9 | legend: 'commits', 10 | legendPosition: 'center', 11 | legendOffset: -40, 12 | } 13 | const axisBottom = { 14 | format, 15 | tickRotation: -60, 16 | } 17 | 18 | export default class RepoCommitActivityHistogramChart extends Component { 19 | static propTypes = { 20 | commits: PropTypes.array.isRequired, 21 | theme: PropTypes.object.isRequired, 22 | } 23 | 24 | render() { 25 | const { commits, theme } = this.props 26 | 27 | return ( 28 | 43 | ) 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/components/stats/charts/RepoCommitActivityLineChart.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react' 2 | import PropTypes from 'prop-types' 3 | import moment from 'moment' 4 | import { ResponsiveLine } from 'nivo' 5 | 6 | const margin = { top: 10, right: 20, bottom: 54, left: 60 } 7 | const format = d => moment.unix(d).format('MM/DD') 8 | const axisLeft = { 9 | legend: 'commits', 10 | legendPosition: 'center', 11 | legendOffset: -40, 12 | } 13 | const axisBottom = { 14 | format, 15 | tickRotation: -60, 16 | } 17 | 18 | export default class RepoCommitActivityLineChart extends Component { 19 | static propTypes = { 20 | commits: PropTypes.array.isRequired, 21 | theme: PropTypes.object.isRequired, 22 | } 23 | 24 | render() { 25 | const { commits, theme } = this.props 26 | 27 | return ( 28 | 38 | ) 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/components/traffic/RepoTrafficClones.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react' 2 | import PropTypes from 'prop-types' 3 | import RepoTrafficClonesHistogramChart from './charts/RepoTrafficClonesHistogramChart' 4 | import RepoTrafficClonesLineChart from './charts/RepoTrafficClonesLineChart' 5 | import { 6 | TrapApiError, 7 | Widget, 8 | WidgetHeader, 9 | WidgetBody, 10 | WidgetLoader, 11 | GithubIcon, 12 | } from '@mozaik/ui' 13 | 14 | export default class RepoTrafficClones extends Component { 15 | static propTypes = { 16 | repository: PropTypes.string.isRequired, 17 | title: PropTypes.string, 18 | apiData: PropTypes.any, 19 | apiError: PropTypes.object, 20 | type: PropTypes.oneOf(['histogram', 'line']).isRequired, 21 | theme: PropTypes.object.isRequired, 22 | } 23 | 24 | static defaultProps = { 25 | type: 'histogram', 26 | } 27 | 28 | static getApiRequest({ repository }) { 29 | return { 30 | id: `github.trafficClones.${repository}`, 31 | params: { repository }, 32 | } 33 | } 34 | 35 | render() { 36 | const { repository, title, type, apiData, apiError, theme } = this.props 37 | 38 | let countNode = null 39 | let body = 40 | if (apiData !== undefined) { 41 | const { count, uniques, clones } = apiData 42 | 43 | countNode = ( 44 | 45 | {count} clones - {uniques} unique clones 46 | 47 | ) 48 | 49 | if (type === 'histogram') { 50 | const chartData = clones.map(({ timestamp, uniques, count }) => ({ 51 | timestamp, 52 | uniques, 53 | others: count - uniques, 54 | })) 55 | 56 | body = 57 | } else if (type === 'line') { 58 | const chartData = [ 59 | { 60 | id: 'total', 61 | data: clones.map(clone => ({ 62 | y: clone.count, 63 | x: clone.timestamp, 64 | })), 65 | }, 66 | { 67 | id: 'uniques', 68 | data: clones.map(clone => ({ 69 | y: clone.uniques, 70 | x: clone.timestamp, 71 | })), 72 | }, 73 | ] 74 | 75 | body = 76 | } 77 | } 78 | 79 | return ( 80 | 81 | 87 | 88 | {body} 89 | 90 | 91 | ) 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /src/components/traffic/RepoTrafficClonesHistogram.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react' 2 | import RepoTrafficClones from './RepoTrafficClones' 3 | 4 | export default class RepoTrafficClonesHistogram extends Component { 5 | static getApiRequest(params) { 6 | return RepoTrafficClones.getApiRequest(params) 7 | } 8 | 9 | render() { 10 | return 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/components/traffic/RepoTrafficClonesLine.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react' 2 | import RepoTrafficClones from './RepoTrafficClones' 3 | 4 | export default class RepoTrafficLineHistogram extends Component { 5 | static getApiRequest(params) { 6 | return RepoTrafficClones.getApiRequest(params) 7 | } 8 | 9 | render() { 10 | return 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/components/traffic/RepoTrafficViews.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react' 2 | import PropTypes from 'prop-types' 3 | import RepoTrafficViewsHistogramChart from './charts/RepoTrafficViewsHistogramChart' 4 | import RepoTrafficViewsLineChart from './charts/RepoTrafficViewsLineChart' 5 | import { TrapApiError, Widget, WidgetHeader, WidgetBody, GithubIcon } from '@mozaik/ui' 6 | 7 | export default class RepoTrafficViews extends Component { 8 | static propTypes = { 9 | repository: PropTypes.string.isRequired, 10 | title: PropTypes.string, 11 | apiData: PropTypes.any, 12 | apiError: PropTypes.object, 13 | type: PropTypes.oneOf(['histogram', 'line']).isRequired, 14 | theme: PropTypes.object.isRequired, 15 | } 16 | 17 | static getApiRequest({ repository }) { 18 | return { 19 | id: `github.trafficViews.${repository}`, 20 | params: { repository }, 21 | } 22 | } 23 | 24 | render() { 25 | const { repository, type, apiData, apiError, theme } = this.props 26 | 27 | let countNode = null 28 | let body = null 29 | if (apiData !== undefined) { 30 | const { count, uniques, views } = apiData 31 | 32 | countNode = ( 33 | 34 | {count} views - {uniques} unique visitors 35 | 36 | ) 37 | 38 | if (type === 'histogram') { 39 | const chartData = views.map(({ timestamp, uniques, count }) => ({ 40 | timestamp, 41 | uniques, 42 | others: count - uniques, 43 | })) 44 | 45 | body = 46 | } else if (type === 'line') { 47 | const chartData = [ 48 | { 49 | id: 'total', 50 | data: views.map(view => ({ 51 | y: view.count, 52 | x: view.timestamp, 53 | })), 54 | }, 55 | { 56 | id: 'uniques', 57 | data: views.map(view => ({ 58 | y: view.uniques, 59 | x: view.timestamp, 60 | })), 61 | }, 62 | ] 63 | 64 | body = 65 | } 66 | } 67 | 68 | return ( 69 | 70 | 76 | 77 | {body} 78 | 79 | 80 | ) 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/components/traffic/RepoTrafficViewsHistogram.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react' 2 | import RepoTrafficViews from './RepoTrafficViews' 3 | 4 | export default class RepoTrafficViewsHistogram extends Component { 5 | static getApiRequest(params) { 6 | return RepoTrafficViews.getApiRequest(params) 7 | } 8 | 9 | render() { 10 | return 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/components/traffic/RepoTrafficViewsLine.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react' 2 | import RepoTrafficViews from './RepoTrafficViews' 3 | 4 | export default class RepoTrafficViewsLine extends Component { 5 | static getApiRequest(params) { 6 | return RepoTrafficViews.getApiRequest(params) 7 | } 8 | 9 | render() { 10 | return 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/components/traffic/charts/RepoTrafficClonesHistogramChart.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react' 2 | import PropTypes from 'prop-types' 3 | import moment from 'moment' 4 | import { ResponsiveBar } from 'nivo' 5 | 6 | const margin = { top: 10, right: 10, bottom: 54, left: 60 } 7 | const format = d => moment(d).format('MM/DD') 8 | const axisLeft = { 9 | legend: 'clones', 10 | legendPosition: 'center', 11 | legendOffset: -40, 12 | } 13 | const axisBottom = { 14 | format, 15 | tickRotation: -60, 16 | } 17 | 18 | export default class RepoTrafficClonesHistogramChart extends Component { 19 | static propTypes = { 20 | clones: PropTypes.array.isRequired, 21 | theme: PropTypes.object.isRequired, 22 | } 23 | 24 | render() { 25 | const { clones, theme } = this.props 26 | 27 | return ( 28 | 42 | ) 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/components/traffic/charts/RepoTrafficClonesLineChart.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react' 2 | import PropTypes from 'prop-types' 3 | import moment from 'moment' 4 | import { ResponsiveLine } from 'nivo' 5 | 6 | const margin = { top: 10, right: 20, bottom: 54, left: 60 } 7 | const format = d => moment(d).format('MM/DD') 8 | const axisLeft = { 9 | legend: 'clones', 10 | legendPosition: 'center', 11 | legendOffset: -40, 12 | } 13 | const axisBottom = { 14 | format, 15 | tickRotation: -60, 16 | } 17 | 18 | export default class RepoTrafficClonesLineChart extends Component { 19 | static propTypes = { 20 | clones: PropTypes.array.isRequired, 21 | theme: PropTypes.object.isRequired, 22 | } 23 | 24 | render() { 25 | const { clones, theme } = this.props 26 | 27 | return ( 28 | 38 | ) 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/components/traffic/charts/RepoTrafficViewsHistogramChart.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react' 2 | import PropTypes from 'prop-types' 3 | import moment from 'moment' 4 | import { ResponsiveBar } from 'nivo' 5 | 6 | const margin = { top: 10, right: 10, bottom: 54, left: 60 } 7 | const format = d => moment(d).format('MM/DD') 8 | const axisLeft = { 9 | legend: 'visitors', 10 | legendPosition: 'center', 11 | legendOffset: -40, 12 | } 13 | const axisBottom = { 14 | format, 15 | tickRotation: -60, 16 | } 17 | 18 | export default class RepoTrafficViewsHistogramChart extends Component { 19 | static propTypes = { 20 | views: PropTypes.array.isRequired, 21 | theme: PropTypes.object.isRequired, 22 | } 23 | 24 | render() { 25 | const { views, theme } = this.props 26 | 27 | return ( 28 | 43 | ) 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/components/traffic/charts/RepoTrafficViewsLineChart.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react' 2 | import PropTypes from 'prop-types' 3 | import moment from 'moment' 4 | import { ResponsiveLine } from 'nivo' 5 | 6 | const margin = { top: 10, right: 20, bottom: 54, left: 60 } 7 | const format = d => moment(d).format('MM/DD') 8 | const axisLeft = { 9 | legend: 'visitors', 10 | legendPosition: 'center', 11 | legendOffset: -40, 12 | } 13 | const axisBottom = { 14 | format, 15 | tickRotation: -60, 16 | } 17 | 18 | export default class RepoTrafficViewsLineChart extends Component { 19 | static propTypes = { 20 | views: PropTypes.array.isRequired, 21 | theme: PropTypes.object.isRequired, 22 | } 23 | 24 | render() { 25 | const { views, theme } = this.props 26 | 27 | return ( 28 | 38 | ) 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/config.js: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the Mozaïk project. 3 | * 4 | * (c) 2016 Raphaël Benitte 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | */ 9 | 10 | const convict = require('convict') 11 | 12 | const config = convict({ 13 | github: { 14 | baseUrl: { 15 | doc: 'The github API base url.', 16 | default: 'https://api.github.com', 17 | format: String, 18 | env: 'GITHUB_BASE_URL', 19 | }, 20 | token: { 21 | doc: 'The github API token.', 22 | default: '', 23 | format: String, 24 | env: 'GITHUB_API_TOKEN', 25 | }, 26 | }, 27 | }) 28 | 29 | module.exports = config 30 | -------------------------------------------------------------------------------- /test/.eslintrc.yml: -------------------------------------------------------------------------------- 1 | globals: 2 | test: true 3 | expect: true 4 | describe: true 5 | it: true 6 | -------------------------------------------------------------------------------- /test/components/badges/OrgBadge.test.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import { shallow } from 'enzyme' 3 | import renderer from 'react-test-renderer' 4 | import { ThemeProvider } from 'styled-components' 5 | import { WidgetHeader, WidgetLoader, defaultTheme } from '@mozaik/ui' 6 | import OrgBadge from './../../../src/components/badges/OrgBadge' 7 | 8 | const sampleOrganization = 'github' 9 | 10 | test('should return correct api request', () => { 11 | expect( 12 | OrgBadge.getApiRequest({ 13 | organization: sampleOrganization, 14 | }) 15 | ).toEqual({ 16 | id: `github.organization.${sampleOrganization}`, 17 | params: { organization: sampleOrganization }, 18 | }) 19 | }) 20 | 21 | test('should display loader if no apiData available', () => { 22 | const wrapper = shallow() 23 | 24 | expect(wrapper.find(WidgetLoader).exists()).toBeTruthy() 25 | }) 26 | 27 | test('should be able to display organization name without api response', () => { 28 | const wrapper = shallow() 29 | 30 | const header = wrapper.find(WidgetHeader) 31 | expect(header.exists()).toBeTruthy() 32 | expect(header.prop('subject')).toBe(sampleOrganization) 33 | }) 34 | 35 | test('should allow title override', () => { 36 | const wrapper = shallow() 37 | 38 | const header = wrapper.find(WidgetHeader) 39 | expect(header.exists()).toBeTruthy() 40 | expect(header.prop('title')).toBe('override') 41 | expect(header.prop('subject')).toBe(null) 42 | }) 43 | 44 | test('should render as expected', () => { 45 | const tree = renderer.create( 46 | 47 | 48 | 49 | ) 50 | 51 | expect(tree).toMatchSnapshot() 52 | }) 53 | -------------------------------------------------------------------------------- /test/components/badges/UserBadge.test.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import { shallow } from 'enzyme' 3 | import renderer from 'react-test-renderer' 4 | import { ThemeProvider } from 'styled-components' 5 | import { WidgetHeader, WidgetLoader, defaultTheme } from '@mozaik/ui' 6 | import UserBadge from './../../../src/components/badges/UserBadge' 7 | 8 | const sampleUser = 'plouc' 9 | 10 | test('should return correct api request', () => { 11 | expect( 12 | UserBadge.getApiRequest({ 13 | user: sampleUser, 14 | }) 15 | ).toEqual({ 16 | id: `github.user.${sampleUser}`, 17 | params: { user: sampleUser }, 18 | }) 19 | }) 20 | 21 | test('should display loader if no apiData available', () => { 22 | const wrapper = shallow() 23 | 24 | expect(wrapper.find(WidgetLoader).exists()).toBeTruthy() 25 | }) 26 | 27 | test('should be able to display user name without api response', () => { 28 | const wrapper = shallow() 29 | 30 | const header = wrapper.find(WidgetHeader) 31 | expect(header.exists()).toBeTruthy() 32 | expect(header.prop('subject')).toBe(sampleUser) 33 | }) 34 | 35 | test('should allow title override', () => { 36 | const wrapper = shallow() 37 | 38 | const header = wrapper.find(WidgetHeader) 39 | expect(header.exists()).toBeTruthy() 40 | expect(header.prop('title')).toBe('override') 41 | expect(header.prop('subject')).toBe(null) 42 | }) 43 | 44 | test('should render as expected', () => { 45 | const tree = renderer.create( 46 | 47 | 58 | 59 | ) 60 | 61 | expect(tree).toMatchSnapshot() 62 | }) 63 | -------------------------------------------------------------------------------- /test/components/badges/__snapshots__/OrgBadge.test.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`should render as expected 1`] = ` 4 |
8 |
11 |
15 | 16 |
19 | github 20 |
21 | organization 22 |
23 |
26 | 37 | 40 | 41 |
42 |
43 |
47 |
50 | 54 | 62 | 63 |
64 |
65 |
66 |
67 | `; 68 | -------------------------------------------------------------------------------- /test/components/badges/__snapshots__/UserBadge.test.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`should render as expected 1`] = ` 4 |
8 |
11 |
15 | 16 |
19 | plouc 20 |
21 | GitHub User 22 |
23 |
26 | 37 | 40 | 41 |
42 |
43 |
47 |
59 | 90 |
99 | 108 | 111 | 10 112 | 113 | 116 | 121 | public repos 122 | 123 | 124 | 125 | 134 | 137 | 11 138 | 139 | 142 | public gists 143 | 144 | 145 | 154 | 157 | 12 158 | 159 | 162 | 167 | followers 168 | 169 | 170 | 171 | 180 | 183 | 13 184 | 185 | 188 | 193 | following 194 | 195 | 196 | 197 | 205 | 208 | company 209 | 210 | 213 | ploucorp 214 | 215 | 216 |
217 |
218 |
219 |
220 |
221 | `; 222 | -------------------------------------------------------------------------------- /test/components/pull-requests/PullRequests.test.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import { shallow } from 'enzyme' 3 | import renderer from 'react-test-renderer' 4 | import { ThemeProvider } from 'styled-components' 5 | import { WidgetHeader, WidgetLoader, defaultTheme } from '@mozaik/ui' 6 | import PullRequests from './../../../src/components/pull-requests/PullRequests' 7 | 8 | const sampleRepository = 'plouc/mozaik' 9 | const samplePullRequests = [ 10 | { 11 | id: 0, 12 | title: 'PR-0', 13 | html_url: 'https://github.com/whatever', 14 | created_at: '2011-10-10T14:48:00', 15 | user: { 16 | avatar_url: 'http://mozaik.rocks/avatar.gif', 17 | html_url: 'https://github.com/whatever', 18 | login: 'plouc', 19 | }, 20 | }, 21 | { 22 | id: 1, 23 | title: 'PR-1', 24 | html_url: 'https://github.com/whatever', 25 | created_at: '2011-10-10T14:48:00', 26 | user: { 27 | avatar_url: 'http://mozaik.rocks/avatar.gif', 28 | html_url: 'https://github.com/whatever', 29 | login: 'john', 30 | }, 31 | }, 32 | { 33 | id: 2, 34 | title: 'PR-2', 35 | html_url: 'https://github.com/whatever', 36 | created_at: '2011-10-10T14:48:00', 37 | user: { 38 | avatar_url: 'http://mozaik.rocks/avatar.gif', 39 | html_url: 'https://github.com/whatever', 40 | login: 'sarah', 41 | }, 42 | }, 43 | ] 44 | 45 | test('should return correct api request', () => { 46 | expect( 47 | PullRequests.getApiRequest({ 48 | repository: sampleRepository, 49 | }) 50 | ).toEqual({ 51 | id: `github.pullRequests.${sampleRepository}`, 52 | params: { repository: sampleRepository }, 53 | }) 54 | }) 55 | 56 | test('should display loader if no apiData available', () => { 57 | const wrapper = shallow() 58 | 59 | expect(wrapper.find(WidgetLoader).exists()).toBeTruthy() 60 | }) 61 | 62 | test('header should display 0 count by default', () => { 63 | const wrapper = shallow() 64 | 65 | const header = wrapper.find(WidgetHeader) 66 | expect(header.prop('count')).toBe(0) 67 | }) 68 | 69 | test('header should display pull request count when api sent data', () => { 70 | const wrapper = shallow( 71 | 75 | ) 76 | 77 | const header = wrapper.find(WidgetHeader) 78 | expect(header.exists()).toBeTruthy() 79 | expect(header.prop('count')).toBe(samplePullRequests.length) 80 | }) 81 | 82 | test(`header title should default to ' Pull Requests'`, () => { 83 | const wrapper = shallow() 84 | 85 | const header = wrapper.find(WidgetHeader) 86 | expect(header.prop('title')).toBe('Pull Requests') 87 | expect(header.prop('subject')).toBe(sampleRepository) 88 | }) 89 | 90 | test(`header title should be overridden when passing 'title' prop`, () => { 91 | const customTitle = 'Custom Title' 92 | const wrapper = shallow() 93 | 94 | const header = wrapper.find(WidgetHeader) 95 | expect(header.prop('title')).toBe(customTitle) 96 | expect(header.prop('subject')).toBe(null) 97 | }) 98 | 99 | test('should render as expected', () => { 100 | const tree = renderer.create( 101 | 102 | 106 | 107 | ) 108 | 109 | expect(tree).toMatchSnapshot() 110 | }) 111 | -------------------------------------------------------------------------------- /test/components/pull-requests/__snapshots__/PullRequests.test.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`should render as expected 1`] = ` 4 |
8 |
11 |
15 | 16 |
19 | plouc/mozaik 20 |
21 | Pull Requests 22 |
25 | 3 26 |
27 |
28 |
31 | 42 | 45 | 46 |
47 |
48 |
52 |
53 |
56 |
59 |
69 | plouc 73 |
74 |
75 |
82 |
85 | 86 | 91 | PR-0 92 | 93 | by 94 | 95 | 100 | plouc 101 | 102 | 103 |
104 |
108 | 116 | 132 | 137 | 140 | 141 |   142 | 7 years ago 143 | 144 |
145 |
146 |
147 |
150 |
153 |
163 | john 167 |
168 |
169 |
176 |
179 | 180 | 185 | PR-1 186 | 187 | by 188 | 189 | 194 | john 195 | 196 | 197 |
198 |
202 | 210 | 226 | 231 | 234 | 235 |   236 | 7 years ago 237 | 238 |
239 |
240 |
241 |
244 |
247 |
257 | sarah 261 |
262 |
263 |
270 |
273 | 274 | 279 | PR-2 280 | 281 | by 282 | 283 | 288 | sarah 289 | 290 | 291 |
292 |
296 | 304 | 320 | 325 | 328 | 329 |   330 | 7 years ago 331 | 332 |
333 |
334 |
335 |
336 |
337 |
338 |
339 | `; 340 | -------------------------------------------------------------------------------- /test/setupTests.js: -------------------------------------------------------------------------------- 1 | import Enzyme from 'enzyme' 2 | import Adapter from 'enzyme-adapter-react-16' 3 | 4 | Enzyme.configure({ adapter: new Adapter() }) 5 | --------------------------------------------------------------------------------