"use strict";
// P R O G R A M
function generateEvent(event) {
switch (event.type) {
case "CommitCommentEvent":
return `
${event.actor.display_login} commented on
commit in
`;
case "CreateEvent":
return `
${event.actor.display_login} created
${event.payload.ref_type} ${event.payload.ref}
in
`;
case "DeleteEvent":
return `
${event.actor.display_login} deleted
${event.payload.ref_type} ${event.payload.ref}
in
`;
case "ForkEvent":
return `
${event.actor.display_login} forked
${event.repo.name} to
${event.payload.forkee.name} in
`;
case "IssueCommentEvent":
if (event.payload.issue.pull_request) {
return `
${event.actor.display_login} commented on pull request
${event.payload.issue.title} in
`;
} else {
return `
${event.actor.display_login} commented on issue
${event.payload.issue.title} in
`;
}
case "IssuesEvent":
return `
${event.actor.display_login} ${event.payload.action} issue
${event.payload.issue.title} in
`;
case "PullRequestEvent":
return `
${event.actor.display_login} ${event.payload.action} pull request
${event.payload.pull_request.title} in
`;
case "PullRequestReviewCommentEvent":
return `
${event.actor.display_login} commented on pull request
${event.payload.pull_request.title} in
`;
case "PushEvent":
return `
${event.actor.display_login} pushed to
${refToBranch(event.payload.ref)}
in
`;
case "ReleaseEvent":
return `
${event.actor.display_login} released
${event.payload.release.tag_name} in
`;
case "WatchEvent":
return `
${event.actor.display_login} starred the repo
`;
default:
break;
}
}
function generateUrl(type, event) {
switch (type) {
case "actor":
return `https://github.com/${event.actor.display_login}`;
case "comment":
return event.payload.comment.html_url;
case "repo":
return `https://github.com/${event.repo.name}`;
case "forkee":
return `https://github.com/${event.payload.forkee.full_name}`;
case "issue":
return event.payload.issue.html_url;
case "pull_request":
return event.payload.pull_request.html_url;
case "release":
return event.payload.release.html_url;
case "push":
return `https://github.com/${event.repo.name}/tree/${event.payload.ref.replace("refs/heads/", "")}`;
default:
break;
}
}
// H E L P E R
function refToBranch(ref) {
return ref.replace("refs/heads/", "");
}
// E X P O R T S
module.exports = exports = {
generateEvent,
generateUrl
};