Skip to content
This repository has been archived by the owner on Sep 12, 2024. It is now read-only.

feat: add opt-out #91

Merged
merged 3 commits into from
Jun 3, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions src/api-user/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ const axios = require("axios").default;
(async () => {
try {
const { payload } = github.context;
const labels = ["EddieHub-API-add", "EddieHub-API-delete"];
const apiKey = core.getInput("api-key", { required: true });
const apiURL = core.getInput("api-url", { required: true });
const repoToken = core.getInput('repo-token', { required: true });
const repoToken = core.getInput("repo-token", { required: true });
const client = github.getOctokit(repoToken);
const currentLabel = payload.label.name;

Expand All @@ -17,29 +18,33 @@ const axios = require("axios").default;
githubUsername: author.login,
};


if (currentLabel === 'EddieHub-API-add') {
if (labels.includes(currentLabel)) {
try {
console.log(body);
await axios.post(apiURL, body, {
headers: { ...authHeader },
});

if (currentLabel === "EddieHub-API-add") {
await axios.post(apiURL, body, {
headers: { ...authHeader },
});
} else {
await axios.delete(`${apiURL}/${author}`, {
headers: { ...authHeader },
});
}
await client.issues.createComment({
owner: payload.repository.owner.login,
repo: payload.repository.name,
issue_number: payload.issue.number,
body: 'You have been ADDED to the EddieHub API',
body: "You have been ADDED to the EddieHub API",
});

await client.issues.update({
owner: payload.repository.owner.login,
repo: payload.repository.name,
issue_number: payload.issue.number,
state: 'closed',
state: "closed",
});
} catch (e) {
console.log(e.response.data)
console.log(e.response.data);
}
}
} catch (error) {
Expand Down