Merge branch 'github-feed'

This commit is contained in:
Kristian Polso 2018-05-12 13:03:52 +03:00
commit 9b6fdbe08a
7 changed files with 320 additions and 3 deletions

4
.gitignore vendored
View file

@ -13,4 +13,6 @@ yarn-error.log*
*.njsproj
*.sln
.vuepress/dist
.vuepress/dist
.env

View file

@ -0,0 +1,112 @@
<template>
<div id="github-feed">
<div class="last-updated" v-on:click="updateFeed">Last updated: {{ formatDate(lastUpdated) }}</div>
<div v-for="event in events" class="event">
<a v-bind:href="event.actor.url" target="_blank">
<img v-bind:src="event.actor.avatar_url" class="avatar"> {{ event.actor.display_login }}
</a>
<template v-if="event.type == 'CommitCommentEvent'">
commented on <a v-bind:href="event.payload.comment.url">commit</a>
</template>
<template v-else-if="event.type == 'CreateEvent'">
created {{ event.payload.ref_type }} '{{ event.payload.ref }}'
</template>
<template v-else-if="event.type == 'DeleteEvent'">
deleted {{ event.payload.ref_type }} '{{ event.payload.ref }}'
</template>
<template v-else-if="event.type == 'ForkEvent'">
forked <a v-bind:href="event.repo.url" target="_blank">{{ event.repo.name }}</a> to <a v-bind:href="event.payload.forkee.url" target="_blank">{{ event.payload.forkee.name }}</a>
</template>
<template v-else-if="event.type == 'IssueCommentEvent'">
commented on <template v-if="event.payload.issue.pull_request">pull request</template><template v-else>issue</template> <a v-bind:href="event.payload.issue.url" target="_blank">{{ event.payload.issue.title }}</a>
</template>
<template v-else-if="event.type == 'IssuesEvent'">
{{ event.payload.action }} issue <a v-bind:href="event.payload.issue.url" target="_blank">{{ event.payload.issue.title }}</a>
</template>
<template v-else-if="event.type == 'PullRequestEvent'">
{{ event.payload.action }} pull request <a v-bind:href="event.payload.pull_request.url" target="_blank">{{ event.payload.pull_request.title }}</a>
</template>
<template v-else-if="event.type == 'PushEvent'">
pushed to <span v-html="refToLink(event.payload.ref, event.repo.name)"></span>
</template>
<template v-else-if="event.type == 'ReleaseEvent'">
released <a v-bind:href="event.payload.release.url" target="_blank">{{ event.payload.release.tag_name }}</a>
</template>
<template v-else-if="event.type == 'WatchEvent'">
starred the repo
</template>
in <a v-bind:href="event.repo.url" target="_blank">{{ event.repo.name }}</a>
</div>
</div>
</template>
<script>
export default {
data () {
return {
events: [],
updateInterval: {},
lastUpdated: new Date()
}
},
name: 'GithubFeed',
mounted () {
this.updateFeed();
this.updateInterval = setInterval(this.updateFeed, 60*1000);
},
methods: {
updateFeed () {
var component = this;
component.$http.get('//beta.lbry.tech/github-feed').then(function(response) {
component.events = response.body;
});
component.lastUpdated = new Date();
},
refToLink (ref, repo) {
return "<a target='_blank' href='https://github.com/" + repo + "/tree/" + ref.replace('refs/heads/','') + "'>" + ref.replace('refs/heads/','') + "</a>";
},
formatDate (date) {
return date.toLocaleString('en-US');
}
}
};
</script>
<style lang="scss">
#github-feed {
.last-updated {
text-align: right;
color: #777;
font-style: italic;
}
.event {
padding: 0.5rem 0;
border-bottom: 1px solid #ccc;
}
.avatar {
width: 2rem;
height: 2rem;
border-radius: 1rem;
vertical-align: middle;
margin-right: 0.5rem;
}
}
</style>

5
github-feed.md Normal file
View file

@ -0,0 +1,5 @@
---
title: Github Feed Example
---
<GithubFeed></GithubFeed>

18
github.js Normal file
View file

@ -0,0 +1,18 @@
require('dotenv').config();
var octokit = require('@octokit/rest')();
var redis = require("redis"),
redisClient = redis.createClient(process.env.REDISCLOUD_URL);
octokit.activity.getEventsForOrg({
org: 'lbryio',
per_page: 20,
page: 1
}).then(function({data}) {
console.log(data);
redisClient.set('events', JSON.stringify(data), redis.print);
});

View file

@ -9,11 +9,16 @@
},
"license": "ISC",
"dependencies": {
"@octokit/rest": "^15.4.0",
"async": "^2.6.0",
"cors": "^2.8.4",
"cron": "^1.3.0",
"dotenv": "^5.0.1",
"express": "^4.16.3",
"heroku-ssl-redirect": "0.0.4",
"highlight.js": "^9.12.0",
"node-sass": "^4.8.3",
"redis": "^2.8.0",
"request": "^2.85.0",
"sass-loader": "^7.0.1",
"vue": "^2.5.16",

View file

@ -1,11 +1,23 @@
// server.js
// env variables
require('dotenv').config();
// Async
var async = require("async");
// Express etc
var sslRedirect = require('heroku-ssl-redirect');
var express = require('express');
var path = require('path');
var serveStatic = require('serve-static');
var request = require('request');
var cors = require('cors');
// Cron
var CronJob = require('cron').CronJob;
// Github API
var octokit = require('@octokit/rest')();
// Redis
var redis = require("redis"),
redisClient = redis.createClient(process.env.REDISCLOUD_URL);
app = express();
app.use(serveStatic(__dirname + "/.vuepress/dist"));
@ -39,7 +51,65 @@ app.get('/forward', function(req, res) {
});
app.get('/github-feed', function(req, res) {
redisClient.zrevrange('events', 0, 9, function(err, reply) {
var events = [];
reply.forEach(function(item) {
events.push(JSON.parse(item));
});
res.json(events);
});
});
var port = process.env.PORT || 8080;
app.listen(port);
console.log('server started '+ port);
function updateGithubFeed() {
octokit.activity.getEventsForOrg({
org: 'lbryio',
per_page: 20,
page: 1
}).then(function({data}) {
async.eachSeries(data, function(item, callback) {
var eventString = JSON.stringify(item);
redisClient.zrank('events', eventString, function(err, reply) {
if(reply == null) {
redisClient.zadd('events', item.id, eventString, callback);
} else {
callback();
}
});
}, function() {
// Keep the latest 50 events
redisClient.zremrangebyrank('events', 0, -51);
console.log('Updated Github feed');
});
});
}
// Update Github feed every minute
new CronJob("0 * * * * *", updateGithubFeed, null, true, 'America/Los_Angeles');

109
yarn.lock
View file

@ -9,6 +9,19 @@
call-me-maybe "^1.0.1"
glob-to-regexp "^0.3.0"
"@octokit/rest@^15.4.0":
version "15.4.0"
resolved "https://registry.yarnpkg.com/@octokit/rest/-/rest-15.4.0.tgz#8d5f08562adf7ddab5668ef243d8fedd283bcd85"
dependencies:
before-after-hook "^1.1.0"
btoa-lite "^1.0.0"
debug "^3.1.0"
http-proxy-agent "^2.1.0"
https-proxy-agent "^2.2.0"
lodash "^4.17.4"
node-fetch "^2.1.1"
url-template "^2.0.8"
"@shellscape/koa-send@^4.1.0":
version "4.1.3"
resolved "https://registry.yarnpkg.com/@shellscape/koa-send/-/koa-send-4.1.3.tgz#1a7c8df21f63487e060b7bfd8ed82e1d3c4ae0b0"
@ -69,6 +82,12 @@ acorn@^5.0.0, acorn@^5.0.3, acorn@^5.4.1:
version "5.5.3"
resolved "https://registry.yarnpkg.com/acorn/-/acorn-5.5.3.tgz#f473dd47e0277a08e28e9bec5aeeb04751f0b8c9"
agent-base@4, agent-base@^4.1.0:
version "4.2.0"
resolved "https://registry.yarnpkg.com/agent-base/-/agent-base-4.2.0.tgz#9838b5c3392b962bad031e6a4c5e1024abec45ce"
dependencies:
es6-promisify "^5.0.0"
agentkeepalive@^2.2.0:
version "2.2.0"
resolved "https://registry.yarnpkg.com/agentkeepalive/-/agentkeepalive-2.2.0.tgz#c5d1bd4b129008f1163f236f86e5faea2026e2ef"
@ -278,6 +297,12 @@ async@^1.5.2:
version "1.5.2"
resolved "https://registry.yarnpkg.com/async/-/async-1.5.2.tgz#ec6a61ae56480c0c3cb241c95618e20892f9672a"
async@^2.6.0:
version "2.6.0"
resolved "https://registry.yarnpkg.com/async/-/async-2.6.0.tgz#61a29abb6fcc026fea77e56d1c6ec53a795951f4"
dependencies:
lodash "^4.14.0"
asynckit@^0.4.0:
version "0.4.0"
resolved "https://registry.yarnpkg.com/asynckit/-/asynckit-0.4.0.tgz#c79ed97f7f34cb8f2ba1bc9790bcc366474b4b79"
@ -371,6 +396,10 @@ bcrypt-pbkdf@^1.0.0:
dependencies:
tweetnacl "^0.14.3"
before-after-hook@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/before-after-hook/-/before-after-hook-1.1.0.tgz#83165e15a59460d13702cb8febd6a1807896db5a"
big.js@^3.1.3:
version "3.2.0"
resolved "https://registry.yarnpkg.com/big.js/-/big.js-3.2.0.tgz#a5fc298b81b9e0dca2e458824784b65c52ba588e"
@ -538,6 +567,10 @@ browserslist@^3.2.4:
caniuse-lite "^1.0.30000821"
electron-to-chromium "^1.3.41"
btoa-lite@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/btoa-lite/-/btoa-lite-1.0.0.tgz#337766da15801210fdd956c22e9c6891ab9d0337"
buble-loader@^0.5.0:
version "0.5.0"
resolved "https://registry.yarnpkg.com/buble-loader/-/buble-loader-0.5.0.tgz#bde97505c2b9310965579c2e4eebfb8d34819968"
@ -1087,6 +1120,12 @@ create-hmac@^1.1.0, create-hmac@^1.1.2, create-hmac@^1.1.4:
safe-buffer "^5.0.1"
sha.js "^2.4.8"
cron@^1.3.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/cron/-/cron-1.3.0.tgz#7e459968eaf94e1a445be796ce402166c234659d"
dependencies:
moment-timezone "^0.5.x"
cross-spawn@^3.0.0:
version "3.0.1"
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-3.0.1.tgz#1256037ecb9f0c5f79e3d6ef135e30770184b982"
@ -1254,7 +1293,7 @@ de-indent@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/de-indent/-/de-indent-1.0.2.tgz#b2038e846dc33baa5796128d0804b455b8c1e21d"
debug@*, debug@^3.1.0:
debug@*, debug@3.1.0, debug@^3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/debug/-/debug-3.1.0.tgz#5bb5a0672628b64149566ba16819e61518c67261"
dependencies:
@ -1446,6 +1485,14 @@ dot-prop@^4.1.0, dot-prop@^4.1.1:
dependencies:
is-obj "^1.0.0"
dotenv@^5.0.1:
version "5.0.1"
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-5.0.1.tgz#a5317459bd3d79ab88cff6e44057a6a3fbb1fcef"
double-ended-queue@^2.1.0-0:
version "2.1.0-0"
resolved "https://registry.yarnpkg.com/double-ended-queue/-/double-ended-queue-2.1.0-0.tgz#103d3527fd31528f40188130c841efdd78264e5c"
duplexer3@^0.1.4:
version "0.1.4"
resolved "https://registry.yarnpkg.com/duplexer3/-/duplexer3-0.1.4.tgz#ee01dd1cac0ed3cbc7fdbea37dc0a8f1ce002ce2"
@ -1552,10 +1599,16 @@ es-to-primitive@^1.1.1:
is-date-object "^1.0.1"
is-symbol "^1.0.1"
es6-promise@^4.1.0, es6-promise@^4.2.4:
es6-promise@^4.0.3, es6-promise@^4.1.0, es6-promise@^4.2.4:
version "4.2.4"
resolved "https://registry.yarnpkg.com/es6-promise/-/es6-promise-4.2.4.tgz#dc4221c2b16518760bd8c39a52d8f356fc00ed29"
es6-promisify@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/es6-promisify/-/es6-promisify-5.0.0.tgz#5109d62f3e56ea967c4b63505aef08291c8a5203"
dependencies:
es6-promise "^4.0.3"
escape-html@^1.0.3, escape-html@~1.0.1, escape-html@~1.0.3:
version "1.0.3"
resolved "https://registry.yarnpkg.com/escape-html/-/escape-html-1.0.3.tgz#0258eae4d3d0c0974de1c169188ef0051d1d1988"
@ -2349,6 +2402,13 @@ http-errors@^1.2.8, http-errors@^1.6.1, http-errors@~1.6.1, http-errors@~1.6.2:
setprototypeof "1.1.0"
statuses ">= 1.4.0 < 2"
http-proxy-agent@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/http-proxy-agent/-/http-proxy-agent-2.1.0.tgz#e4821beef5b2142a2026bd73926fe537631c5405"
dependencies:
agent-base "4"
debug "3.1.0"
http-signature@~1.1.0:
version "1.1.1"
resolved "https://registry.yarnpkg.com/http-signature/-/http-signature-1.1.1.tgz#df72e267066cd0ac67fb76adf8e134a8fbcf91bf"
@ -2369,6 +2429,13 @@ https-browserify@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/https-browserify/-/https-browserify-1.0.0.tgz#ec06c10e0a34c0f2faf199f7fd7fc78fffd03c73"
https-proxy-agent@^2.2.0:
version "2.2.1"
resolved "https://registry.yarnpkg.com/https-proxy-agent/-/https-proxy-agent-2.2.1.tgz#51552970fa04d723e04c56d04178c3f92592bbc0"
dependencies:
agent-base "^4.1.0"
debug "^3.1.0"
iconv-lite@0.4.19:
version "0.4.19"
resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.19.tgz#f7468f60135f5e5dad3399c0a81be9a1603a082b"
@ -3101,6 +3168,10 @@ lodash@^4.0.0, lodash@^4.17.3, lodash@^4.17.4, lodash@^4.17.5, lodash@~4.17.4:
version "4.17.5"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.5.tgz#99a92d65c0272debe8c96b6057bc8fbfa3bed511"
lodash@^4.14.0:
version "4.17.10"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.10.tgz#1b7793cf7259ea38fb3661d4d38b3260af8ae4e7"
log-symbols@^2.1.0:
version "2.2.0"
resolved "https://registry.yarnpkg.com/log-symbols/-/log-symbols-2.2.0.tgz#5740e1c5d6f0dfda4ad9323b5332107ef6b4c40a"
@ -3415,6 +3486,16 @@ mkdirp@0.5.x, "mkdirp@>=0.5 0", mkdirp@^0.5.0, mkdirp@^0.5.1, mkdirp@~0.5.0, mkd
dependencies:
minimist "0.0.8"
moment-timezone@^0.5.x:
version "0.5.17"
resolved "https://registry.yarnpkg.com/moment-timezone/-/moment-timezone-0.5.17.tgz#3c8fef32051d84c3af174d91dc52977dcb0ad7e5"
dependencies:
moment ">= 2.9.0"
"moment@>= 2.9.0":
version "2.22.1"
resolved "https://registry.yarnpkg.com/moment/-/moment-2.22.1.tgz#529a2e9bf973f259c9643d237fda84de3a26e8ad"
move-concurrently@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/move-concurrently/-/move-concurrently-1.0.1.tgz#be2c005fda32e0b29af1f05d7c4b33214c701f92"
@ -3501,6 +3582,10 @@ no-case@^2.2.0:
dependencies:
lower-case "^1.1.1"
node-fetch@^2.1.1:
version "2.1.2"
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.1.2.tgz#ab884e8e7e57e38a944753cec706f788d1768bb5"
node-gyp@^3.3.1:
version "3.6.2"
resolved "https://registry.yarnpkg.com/node-gyp/-/node-gyp-3.6.2.tgz#9bfbe54562286284838e750eac05295853fa1c60"
@ -4514,6 +4599,22 @@ redent@^2.0.0:
indent-string "^3.0.0"
strip-indent "^2.0.0"
redis-commands@^1.2.0:
version "1.3.5"
resolved "https://registry.yarnpkg.com/redis-commands/-/redis-commands-1.3.5.tgz#4495889414f1e886261180b1442e7295602d83a2"
redis-parser@^2.6.0:
version "2.6.0"
resolved "https://registry.yarnpkg.com/redis-parser/-/redis-parser-2.6.0.tgz#52ed09dacac108f1a631c07e9b69941e7a19504b"
redis@^2.8.0:
version "2.8.0"
resolved "https://registry.yarnpkg.com/redis/-/redis-2.8.0.tgz#202288e3f58c49f6079d97af7a10e1303ae14b02"
dependencies:
double-ended-queue "^2.1.0-0"
redis-commands "^1.2.0"
redis-parser "^2.6.0"
reduce-css-calc@^1.2.6:
version "1.3.0"
resolved "https://registry.yarnpkg.com/reduce-css-calc/-/reduce-css-calc-1.3.0.tgz#747c914e049614a4c9cfbba629871ad1d2927716"
@ -5622,6 +5723,10 @@ url-parse-lax@^3.0.0:
dependencies:
prepend-http "^2.0.0"
url-template@^2.0.8:
version "2.0.8"
resolved "https://registry.yarnpkg.com/url-template/-/url-template-2.0.8.tgz#fc565a3cccbff7730c775f5641f9555791439f21"
url-to-options@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/url-to-options/-/url-to-options-1.0.1.tgz#1505a03a289a48cbd7a434efbaeec5055f5633a9"