Skip to content

Commit 45fe913

Browse files
author
gitopia1gyrcgtfa8lqmytl5svv3y8s439l7xhccgh8q4p
committed
Merge pull request #4 from gitopia-slack-bot/handle-comment-event
2 parents 0444cd5 + 904d78f commit 45fe913

File tree

3 files changed

+48
-4
lines changed

3 files changed

+48
-4
lines changed

index.js

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const express = require("express");
66
const bodyParser = require("body-parser");
77
const { WS_ADDR } = require("./config");
88
const {
9+
getUser,
910
getUsername,
1011
resolveAddress,
1112
getRepoDetails,
@@ -533,11 +534,29 @@ function connect() {
533534
}
534535
break;
535536
}
536-
case "/gitopia.gitopia.gitopia.MsgCreateComment": {
537-
blocks.push(
538-
generateSectionBlock("New comment somewhere :man-shrugging:")
539-
);
537+
case "CreateComment": {
538+
try {
539+
const { repoOwnerName, repositoryName } = await getRepoDetails(
540+
eventAttributes["RepositoryId"]
541+
);
542+
const username = await getUsername(eventAttributes["Creator"]);
540543

544+
let section = generateSectionBlock(
545+
`<https://gitopia.com/${username}|${username}> commented: "${eventAttributes["CommentBody"]}" on <https://gitopia.com/${repoOwnerName}/${repositoryName}/issues/${eventAttributes["CommentParentIid"]}|${repoOwnerName}/${repositoryName} #${eventAttributes["CommentParentIid"]}>`
546+
);
547+
548+
const user = await getUser(eventAttributes["Creator"]);
549+
if (user.avatarUrl) {
550+
section.accessory = {
551+
type: "image",
552+
image_url: user.avatarUrl,
553+
alt_text: "user avatar",
554+
};
555+
}
556+
blocks.push(section);
557+
} catch (error) {
558+
console.error(`Error getting repository details: ${error}`);
559+
}
541560
break;
542561
}
543562
case "ForkRepository": {

jsconfig.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"compilerOptions": {
3+
"module": "ESNext",
4+
"moduleResolution": "Node",
5+
"target": "ES2020",
6+
"jsx": "react",
7+
"strictNullChecks": true,
8+
"strictFunctionTypes": true
9+
},
10+
"exclude": [
11+
"node_modules",
12+
"**/node_modules/*"
13+
]
14+
}

util.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
const axios = require("axios");
22
const { GITOPIA_API_URL } = require("./config");
33

4+
async function getUser(address) {
5+
const response = await axios.get(`${GITOPIA_API_URL}/user/${address}`);
6+
7+
if (response.data) {
8+
return response.data.User;
9+
}
10+
11+
return null;
12+
}
13+
414
async function getUsername(address) {
515
const response = await axios.get(`${GITOPIA_API_URL}/user/${address}`);
616

@@ -84,6 +94,7 @@ const postToSlack = async (web, subscriptions, repoOwnerName, blocks) => {
8494
};
8595

8696
module.exports = {
97+
getUser,
8798
getUsername,
8899
getDAOname,
89100
resolveAddress,

0 commit comments

Comments
 (0)