diff options
author | Bruno de Oliveira Abinader <bruno@mapbox.com> | 2019-03-28 09:38:45 +0200 |
---|---|---|
committer | Bruno de Oliveira Abinader <bruno@mapbox.com> | 2019-03-28 10:13:54 +0200 |
commit | abccf6fa8ab445c9a874c7be7fb9c411e66bf1af (patch) | |
tree | 43786007ae5bfa394f0846ecf6dcc5b027d9a90d | |
parent | 0ec89454503befbbfe628c1677955e23911e75c7 (diff) | |
download | qtlocation-mapboxgl-abccf6fa8ab445c9a874c7be7fb9c411e66bf1af.tar.gz |
[build] Metrics: publish Github Stats
-rw-r--r-- | circle.yml | 16 | ||||
-rw-r--r-- | package.json | 2 | ||||
-rwxr-xr-x | scripts/publish_github_stats.js | 136 |
3 files changed, 153 insertions, 1 deletions
diff --git a/circle.yml b/circle.yml index 063df5573b..97fad16c73 100644 --- a/circle.yml +++ b/circle.yml @@ -66,6 +66,7 @@ workflows: only: - master jobs: + - metrics-nightly - ios-release-template: name: ios-release-nightly - ios-sanitize-nightly @@ -952,6 +953,21 @@ jobs: - upload-xcode-build-logs # ------------------------------------------------------------------------------ + metrics-nightly: + docker: + - image: mbgl/linux-gcc-5:54f59e3ac5 + working_directory: /src + environment: + LIBSYSCONFCPUS: 2 + JOBS: 2 + steps: + - install-dependencies + - run: + name: Collect GitHub statistics + command: | + scripts/publish_github_stats.js + +# ------------------------------------------------------------------------------ ios-sanitize-nightly: macos: xcode: "10.1.0" diff --git a/package.json b/package.json index 7462ab751e..72a12cada6 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "npm-run-all": "^4.0.2" }, "devDependencies": { - "@octokit/rest": "^15.15.1", + "@octokit/rest": "^16.21.0", "aws-sdk": "^2.285.1", "csscolorparser": "^1.0.2", "ejs": "^2.4.1", diff --git a/scripts/publish_github_stats.js b/scripts/publish_github_stats.js new file mode 100755 index 0000000000..7dbcbac29a --- /dev/null +++ b/scripts/publish_github_stats.js @@ -0,0 +1,136 @@ +#!/usr/bin/env node + +const jwt = require('jsonwebtoken'); +const github = require('@octokit/rest')(); +const zlib = require('zlib'); +const AWS = require('aws-sdk'); + +const SIZE_CHECK_APP_ID = 14028; +const SIZE_CHECK_APP_INSTALLATION_ID = 229425; + +// Error handling + +process.on('unhandledRejection', error => { + console.log(error); + process.exit(1) +}); + +// Github authorization + +const pk = process.env['SIZE_CHECK_APP_PRIVATE_KEY']; +if (!pk) { + console.log('Fork PR; not publishing size.'); + process.exit(0); +} + +const key = Buffer.from(pk, 'base64').toString('binary'); +const payload = { + exp: Math.floor(Date.now() / 1000) + 60, + iat: Math.floor(Date.now() / 1000), + iss: SIZE_CHECK_APP_ID +}; + +const token = jwt.sign(payload, key, {algorithm: 'RS256'}); +github.authenticate({type: 'app', token}); + +// Metrics: Github statistics + +function collectMetricsFromGithubIssues(issues) { + + const oneMonthAgo = function() { let date = new Date(); date.setMonth(date.getMonth() - 1); return date; }(); + + // Metrics + let openIssuesTotal = 0; + let openIssuesTotalFromNonMembers = 0; + let openIssuesTotalCore = 0; + let openIssuesTotalAndroid = 0; + let openIssuesTotalIOS = 0; + let openIssuesTotalGLJSParity = 0; + let openPullRequestsTotal = 0; + let openPullRequestsTotalFromNonMembers = 0; + let openPullRequestsSinceLastMonth = 0; + let openPullRequestsSinceLastMonthFromNonMembers = 0; + + issues.forEach(function (data) { + let issueCreatedAt = new Date(data.created_at); + let isMapboxAuthor = data.author_association === "MEMBER"; + + if (data.pull_request) { + openPullRequestsTotal++; + if (!isMapboxAuthor) { + openPullRequestsTotalFromNonMembers++; + } + if (issueCreatedAt >= oneMonthAgo) { + openPullRequestsSinceLastMonth++; + if (!isMapboxAuthor) { + openPullRequestsSinceLastMonthFromNonMembers++; + } + } + } else { + openIssuesTotal++; + if (data.author_association !== "MEMBER") { + openIssuesTotalFromNonMembers++; + } + data.labels.forEach(function (label) { + switch (label.name) { + case "Core": + openIssuesTotalCore++; + break; + case "Android": + openIssuesTotalAndroid++; + break; + case "iOS": + openIssuesTotalIOS++; + break; + case "GL JS parity": + openIssuesTotalGLJSParity++; + break; + default: + break; + } + }); + } + }); + + return { + 'created_at': new Date().toISOString().substring(0, 10), + 'open_issues_total': openIssuesTotal, + 'open_issues_total_from_non_members': openIssuesTotalFromNonMembers, + 'open_issues_total_core': openIssuesTotalCore, + 'open_issues_total_android': openIssuesTotalAndroid, + 'open_issues_total_ios': openIssuesTotalIOS, + 'open_issues_total_gl_js_parity': openIssuesTotalGLJSParity, + 'open_pull_requests_total': openPullRequestsTotal, + 'open_pull_requests_total_from_non_members': openPullRequestsTotalFromNonMembers, + 'open_pull_requests_since_last_month': openPullRequestsSinceLastMonth, + 'open_pull_requests_since_last_month_from_non_members': openPullRequestsSinceLastMonthFromNonMembers + }; +}; + +github.apps.createInstallationToken({ installation_id: SIZE_CHECK_APP_INSTALLATION_ID }) + .then(({data}) => { + github.authenticate({ type: 'token', token: data.token }); + }) + .then(() => { + github.paginate(github.issues.listForRepo.endpoint.merge({ owner: 'mapbox', repo: 'mapbox-gl-native', state: 'open', per_page: 100 })); + }) + .then(issues => { + + let metrics = collectMetricsFromGithubIssues(issues); + + var promise = new AWS.S3({region: 'us-east-1'}).putObject({ + Body: zlib.gzipSync(metrics), + Bucket: 'mapbox-loading-dock', + Key: `raw/mobile_staging.github_stats/${metrics['created_at']}/METRIC.json.gz`, + CacheControl: 'max-age=300', + ContentEncoding: 'gzip', + ContentType: 'application/json' + }).promise(); + + return Promise.all([promise]).then(data => { + return console.log("Successfully uploaded Github Stats metrics to S3"); + }).catch(err => { + console.log("Error uploading Github Stats metrics to S3 " + err.message); + return err; + }); + }); |