Correct Github urls

This commit is contained in:
Kristian Polso 2018-05-12 21:13:12 +03:00
parent 60e8ba04ad
commit 4d8e6b735e

View file

@ -5,11 +5,11 @@
<div class="last-updated" v-on:click="updateFeed">Last updated: {{ formatDate(lastUpdated) }}</div> <div class="last-updated" v-on:click="updateFeed">Last updated: {{ formatDate(lastUpdated) }}</div>
<div v-for="event in events" class="event"> <div v-for="event in events" class="event">
<a v-bind:href="event.actor.url" target="_blank"> <a v-bind:href="generateGithubUrl('actor',event)" target="_blank">
<img v-bind:src="event.actor.avatar_url" class="avatar"> {{ event.actor.display_login }} <img v-bind:src="event.actor.avatar_url" class="avatar"> {{ event.actor.display_login }}
</a> </a>
<template v-if="event.type == 'CommitCommentEvent'"> <template v-if="event.type == 'CommitCommentEvent'">
commented on <a v-bind:href="event.payload.comment.url">commit</a> commented on <a v-bind:href="generateGithubUrl('comment', event)">commit</a>
</template> </template>
<template v-else-if="event.type == 'CreateEvent'"> <template v-else-if="event.type == 'CreateEvent'">
created {{ event.payload.ref_type }} '{{ event.payload.ref }}' created {{ event.payload.ref_type }} '{{ event.payload.ref }}'
@ -18,30 +18,30 @@
deleted {{ event.payload.ref_type }} '{{ event.payload.ref }}' deleted {{ event.payload.ref_type }} '{{ event.payload.ref }}'
</template> </template>
<template v-else-if="event.type == 'ForkEvent'"> <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> forked <a v-bind:href="generateGithubUrl('repo', event)" target="_blank">{{ event.repo.name }}</a> to <a v-bind:href="generateGithubUrl('forkee', event)" target="_blank">{{ event.payload.forkee.name }}</a>
</template> </template>
<template v-else-if="event.type == 'IssueCommentEvent'"> <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>&nbsp;<a v-bind:href="event.payload.issue.url" target="_blank">{{ event.payload.issue.title }}</a> commented on <template v-if="event.payload.issue.pull_request">pull request</template><template v-else>issue</template>&nbsp;<a v-bind:href="generateGithubUrl('issue', event)" target="_blank">{{ event.payload.issue.title }}</a>
</template> </template>
<template v-else-if="event.type == 'IssuesEvent'"> <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> {{ event.payload.action }} issue <a v-bind:href="generateGithubUrl('issue', event)" target="_blank">{{ event.payload.issue.title }}</a>
</template> </template>
<template v-else-if="event.type == 'PullRequestEvent'"> <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> {{ event.payload.action }} pull request <a v-bind:href="generateGithubUrl('pull_request', event)" target="_blank">{{ event.payload.pull_request.title }}</a>
</template> </template>
<template v-else-if="event.type == 'PullRequestReviewCommentEvent'"> <template v-else-if="event.type == 'PullRequestReviewCommentEvent'">
commented on pull request <a v-bind:href="event.payload.pull_request.url" target="_blank">{{ event.payload.pull_request.title }}</a> commented on pull request <a v-bind:href="generateGithubUrl('pull_request', event)" target="_blank">{{ event.payload.pull_request.title }}</a>
</template> </template>
<template v-else-if="event.type == 'PushEvent'"> <template v-else-if="event.type == 'PushEvent'">
pushed to <span v-html="refToLink(event.payload.ref, event.repo.name)"></span> pushed to <a v-bind:href="generateGithubUrl('push', event)" target="_blank">{{ refToBranch(event.payload.ref) }}</a>
</template> </template>
<template v-else-if="event.type == 'ReleaseEvent'"> <template v-else-if="event.type == 'ReleaseEvent'">
released <a v-bind:href="event.payload.release.url" target="_blank">{{ event.payload.release.tag_name }}</a> released <a v-bind:href="generateGithubUrl('release', event)" target="_blank">{{ event.payload.release.tag_name }}</a>
</template> </template>
<template v-else-if="event.type == 'WatchEvent'"> <template v-else-if="event.type == 'WatchEvent'">
starred the repo starred the repo
</template> </template>
in <a v-bind:href="event.repo.url" target="_blank">{{ event.repo.name }}</a> in <a v-bind:href="generateGithubUrl('repo', event)" target="_blank">{{ event.repo.name }}</a>
<div class="time-ago">{{ event.created_at | moment('from') }}</div> <div class="time-ago">{{ event.created_at | moment('from') }}</div>
</div> </div>
@ -78,15 +78,57 @@ export default {
component.lastUpdated = new Date(); component.lastUpdated = new Date();
}, },
refToLink (ref, repo) { refToBranch (ref) {
return "<a target='_blank' href='https://github.com/" + repo + "/tree/" + ref.replace('refs/heads/','') + "'>" + ref.replace('refs/heads/','') + "</a>"; return ref.replace('refs/heads/','');
}, },
formatDate (date) { formatDate (date) {
return date.toLocaleString('en-US'); return date.toLocaleString('en-US');
},
generateGithubUrl (type, event) {
switch(type) {
case 'actor':
return 'https://github.com/' + event.actor.display_login;
break;
case 'comment':
return event.payload.comment.html_url;
break;
case 'repo':
return 'https://github.com' + event.repo.name;
break;
case 'forkee':
return 'https://github.com' + event.payload.forkee.full_name;
break;
case 'issue':
return event.payload.issue.html_url;
break;
case 'pull_request':
return event.payload.pull_request.html_url;
break;
case 'release':
return event.payload.release.html_url;
break;
case 'push':
return 'https://github.com/' + event.repo.name + '/tree/' + event.payload.ref.replace('refs/heads/','');
break;
}
},
rewriteGithubApiUrl (url) {
url = url.replace('api.github.com', 'github.com');
var urlParts = url.split('/');
urlParts.push(urlParts.splice(4).join('/'));
return urlParts[0] + '/' + urlParts[1] + '/' + urlParts[2] + '/' + urlParts[4];
} }
} }
}; };