mirror of
https://github.com/hernikplays/freelo-action.git
synced 2024-11-14 04:28:07 +01:00
chore: add built JS file (hook)
This commit is contained in:
parent
b5ab2d9b0c
commit
9c54baee5e
1 changed files with 48 additions and 20 deletions
68
dist/index.js
vendored
68
dist/index.js
vendored
|
@ -45310,6 +45310,9 @@ var axios_default = axios;
|
||||||
// src/index.ts
|
// src/index.ts
|
||||||
var import_sanitize_html = __toESM(require_sanitize_html(), 1);
|
var import_sanitize_html = __toESM(require_sanitize_html(), 1);
|
||||||
import {readFile} from "node:fs/promises";
|
import {readFile} from "node:fs/promises";
|
||||||
|
var freeloMention = function(username) {
|
||||||
|
return Object.keys(userPairing).includes(username) ? `<div><span data-freelo-mention="1" data-freelo-user-id="${userPairing[username]}">@${username}</span></div>` : `<a href="https://github.com/${username}">${username}</a>`;
|
||||||
|
};
|
||||||
var email = core.getInput("email");
|
var email = core.getInput("email");
|
||||||
var apiKey = core.getInput("api-key");
|
var apiKey = core.getInput("api-key");
|
||||||
var projectId = core.getInput("project-id");
|
var projectId = core.getInput("project-id");
|
||||||
|
@ -45325,14 +45328,29 @@ var action = github.context.payload.action;
|
||||||
var issue = github.context.payload.issue;
|
var issue = github.context.payload.issue;
|
||||||
var comment = github.context.payload.comment;
|
var comment = github.context.payload.comment;
|
||||||
var apiEndpoint = "https://api.freelo.io/v1";
|
var apiEndpoint = "https://api.freelo.io/v1";
|
||||||
var defaultHeaders = {
|
var defaultOptions = {
|
||||||
"User-Agent": "Freelo GitHub Action/1.0.0",
|
auth: {
|
||||||
"Content-Type": "application/json"
|
username: email,
|
||||||
|
password: apiKey
|
||||||
|
},
|
||||||
|
headers: {
|
||||||
|
"User-Agent": "Freelo GitHub Action/1.0.0",
|
||||||
|
"Content-Type": "application/json"
|
||||||
|
}
|
||||||
};
|
};
|
||||||
var sanitizeOptions = {
|
var sanitizeOptions = {
|
||||||
allowedTags: ["a", "p", "i", "b", "strong"],
|
allowedTags: ["a", "p", "i", "b", "strong"],
|
||||||
allowedAttributes: false
|
allowedAttributes: false
|
||||||
};
|
};
|
||||||
|
var userPairing = {};
|
||||||
|
try {
|
||||||
|
for (const u of (await readFile("./.github/freelo.txt", { encoding: "utf-8" })).split("\n")) {
|
||||||
|
const p = u.split(":");
|
||||||
|
userPairing[p[0]] = p[1];
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.log("No valid freelo.txt found in .github folder, skipping");
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
if (!action) {
|
if (!action) {
|
||||||
throw new Error("No action was passed");
|
throw new Error("No action was passed");
|
||||||
|
@ -45347,21 +45365,14 @@ try {
|
||||||
if (!tasklistId && !taskId) {
|
if (!tasklistId && !taskId) {
|
||||||
throw new Error("Either task-id or tasklist-id needs to be set!");
|
throw new Error("Either task-id or tasklist-id needs to be set!");
|
||||||
}
|
}
|
||||||
let userPairing;
|
|
||||||
try {
|
|
||||||
userPairing = (await readFile("./.github/freelo.txt", { encoding: "utf-8" })).split("\n");
|
|
||||||
} catch (e) {
|
|
||||||
console.log("No freelo.txt found in .github folder, skipping");
|
|
||||||
}
|
|
||||||
if (tasklistId) {
|
if (tasklistId) {
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case "opened": {
|
case "opened": {
|
||||||
const author = userPairing && userPairing.filter((u) => u.includes(issue.user.login)).length > 0 ? `<div><span data-freelo-mention="1" data-freelo-user-id="${userPairing.filter((u) => u.includes(issue.user.login))[0].split(":")[1]}">@${issue.user.login}</span></div>` : `<a href="https://github.com/${issue.user.login}">${issue.user.login}</a>`;
|
|
||||||
console.log(userPairing?.filter((u) => u.includes(issue.user.login)).length);
|
|
||||||
const taskComment = `
|
const taskComment = `
|
||||||
Created by: ${author}<br>
|
Created by: ${freeloMention(issue.user.login)}<br>
|
||||||
Description: ${import_sanitize_html.default(issue.body ?? "None", sanitizeOptions)}<br>
|
Description: ${import_sanitize_html.default(issue.body ?? "None", sanitizeOptions)}<br>
|
||||||
GitHub issue: <a href="${issue.url}">#${issue.number}</a><br>
|
GitHub issue: <a href="${issue.url}">#${issue.number}</a><br>
|
||||||
|
Assigned to: ${issue.assignee ? `${freeloMention(issue.assignee.login)}` : "Nobody"}<br>
|
||||||
<i>(This action was performed automatically)</i>
|
<i>(This action was performed automatically)</i>
|
||||||
`;
|
`;
|
||||||
const taskContent = {
|
const taskContent = {
|
||||||
|
@ -45370,13 +45381,7 @@ try {
|
||||||
content: taskComment
|
content: taskComment
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
const res = await axios_default.post(`${apiEndpoint}/project/${projectId}/tasklist/${tasklistId}/tasks`, taskContent, {
|
const res = await axios_default.post(`${apiEndpoint}/project/${projectId}/tasklist/${tasklistId}/tasks`, taskContent, defaultOptions);
|
||||||
headers: defaultHeaders,
|
|
||||||
auth: {
|
|
||||||
username: email,
|
|
||||||
password: apiKey
|
|
||||||
}
|
|
||||||
});
|
|
||||||
if (res.status > 399) {
|
if (res.status > 399) {
|
||||||
console.error(res.data);
|
console.error(res.data);
|
||||||
throw new Error("Got an error response from Freelo API");
|
throw new Error("Got an error response from Freelo API");
|
||||||
|
@ -45391,8 +45396,31 @@ try {
|
||||||
}
|
}
|
||||||
case "edited":
|
case "edited":
|
||||||
break;
|
break;
|
||||||
case "closed":
|
case "closed": {
|
||||||
|
const comment2 = (await octokit.rest.issues.listComments({
|
||||||
|
owner: github.context.payload.repository?.owner.login ?? "",
|
||||||
|
repo: github.context.payload.repository?.name ?? "",
|
||||||
|
issue_number: issue.number,
|
||||||
|
mediaType: {
|
||||||
|
format: "html"
|
||||||
|
}
|
||||||
|
})).data.filter((i) => i.user?.login === "github-actions" && i.user.type === "Bot");
|
||||||
|
if (comment2.length === 0)
|
||||||
|
break;
|
||||||
|
console.log(comment2.length);
|
||||||
|
console.log(comment2[0].body_html);
|
||||||
|
const taskId2 = /https:\/\/app.freelo.io\/task\/(\d+)/.exec(comment2[0].body_html ?? "");
|
||||||
|
if (!taskId2 || taskId2.length === 0) {
|
||||||
|
console.log("Comment found, but no Freelo task ID identified");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
const res = await axios_default.post(`${apiEndpoint}/task/${taskId2[1]}`, null, defaultOptions);
|
||||||
|
if (res.status > 399) {
|
||||||
|
console.error(res.data);
|
||||||
|
throw new Error("Got an error response from Freelo API");
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case "reopened":
|
case "reopened":
|
||||||
break;
|
break;
|
||||||
case "assigned":
|
case "assigned":
|
||||||
|
|
Loading…
Reference in a new issue