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

Commit

Permalink
feat: add opt-out (#91)
Browse files Browse the repository at this point in the history
* feat: add opt-out

* fix: add different message

* refactor: opt-out logic
  • Loading branch information
Cahllagerfeld authored Jun 3, 2022
1 parent ff9f58f commit 1bc1f02
Showing 1 changed file with 29 additions and 15 deletions.
44 changes: 29 additions & 15 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,42 @@ 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 },
});

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',
});
if (currentLabel === "EddieHub-API-add") {
await axios.post(apiURL, body, {
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",
});
}
if (currentLabel === "EddieHub-API-delete") {
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 REMOVED from 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

0 comments on commit 1bc1f02

Please sign in to comment.