Skip to content

Commit

Permalink
fix import statement error
Browse files Browse the repository at this point in the history
  • Loading branch information
adarsh-jha-dev committed Nov 28, 2024
1 parent 5d1b69f commit 102c0f9
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 76 deletions.
150 changes: 75 additions & 75 deletions .github/scripts/badge-automation.js
Original file line number Diff line number Diff line change
@@ -1,90 +1,90 @@
const { Octokit } = require("@octokit/rest");
const nodemailer = require("nodemailer");
const fs = require("fs").promises;
const path = require("path");

const octokit = new Octokit({ auth: process.env.GITHUB_TOKEN });

const BADGE_MESSAGES = {
firstTime:
"🎉 Congratulations on your first contribution! Your PR has been merged, and you've earned the First-Time Contributor Badge! Welcome to the Chimoney open-source community, and we can't wait to see what you'll build next! 🌟",
everyMerge:
"🚀 Congratulations! Your PR has been successfully merged, and here's your badge for a fantastic contribution. Keep up the great work, and thank you for being a part of the Chimoney community!",
fourthMerge:
"🌟 Outstanding achievement! You've successfully merged four PRs! Thank you for your continued contributions to the Chimoney community—we truly appreciate your dedication!",
};

async function getBadgeInfo(username) {
const { data: prs } = await octokit.pulls.list({
owner: process.env.GITHUB_REPOSITORY_OWNER,
repo: process.env.GITHUB_REPOSITORY.split("/")[1],
state: "closed",
head: username,
});

const mergedPRs = prs.filter((pr) => pr.merged_at !== null);
const prCount = mergedPRs.length;

return {
firstPR: prCount === 1,
secondOrThirdPR: prCount === 2 || prCount === 3,
fourthPR: prCount === 4,
prCount: prCount,
async function main() {
const { Octokit } = await import("@octokit/rest");
const octokit = new Octokit({ auth: process.env.GITHUB_TOKEN });

const BADGE_MESSAGES = {
firstTime:
"🎉 Congratulations on your first contribution! Your PR has been merged, and you've earned the First-Time Contributor Badge! Welcome to the Chimoney open-source community, and we can't wait to see what you'll build next! 🌟",
everyMerge:
"🚀 Congratulations! Your PR has been successfully merged, and here's your badge for a fantastic contribution. Keep up the great work, and thank you for being a part of the Chimoney community!",
fourthMerge:
"🌟 Outstanding achievement! You've successfully merged four PRs! Thank you for your continued contributions to the Chimoney community—we truly appreciate your dedication!",
};
}

async function postGitHubComment(issueNumber, message) {
await octokit.issues.createComment({
owner: process.env.GITHUB_REPOSITORY_OWNER,
repo: process.env.GITHUB_REPOSITORY.split("/")[1],
issue_number: issueNumber,
body: message,
});
}

async function sendEmail(email, message, badgeInfo) {
const transporter = nodemailer.createTransport({
service: "gmail",
auth: {
user: process.env.EMAIL_USER,
pass: process.env.EMAIL_PASS,
},
});

let badgeFilename;
if (badgeInfo.firstPR) {
badgeFilename = "PR1.png";
} else if (badgeInfo.secondOrThirdPR) {
badgeFilename = `PR${badgeInfo.prCount}.png`;
} else if (badgeInfo.fourthPR) {
badgeFilename = "PR4.png";
async function getBadgeInfo(username) {
const { data: prs } = await octokit.pulls.list({
owner: process.env.GITHUB_REPOSITORY_OWNER,
repo: process.env.GITHUB_REPOSITORY.split("/")[1],
state: "closed",
head: username,
});

const mergedPRs = prs.filter((pr) => pr.merged_at !== null);
const prCount = mergedPRs.length;

return {
firstPR: prCount === 1,
secondOrThirdPR: prCount === 2 || prCount === 3,
fourthPR: prCount === 4,
prCount: prCount,
};
}

const badgeAttachment = {
filename: badgeFilename,
path: path.join(__dirname, `../badges/${badgeFilename}`),
};
async function postGitHubComment(issueNumber, message) {
await octokit.issues.createComment({
owner: process.env.GITHUB_REPOSITORY_OWNER,
repo: process.env.GITHUB_REPOSITORY.split("/")[1],
issue_number: issueNumber,
body: message,
});
}

await transporter.sendMail({
from: process.env.EMAIL_USER,
to: email,
subject: "Congratulations on your merged PR!",
text: message,
attachments: [badgeAttachment],
});
}
async function sendEmail(email, message, badgeInfo) {
const transporter = nodemailer.createTransport({
service: "gmail",
auth: {
user: process.env.EMAIL_USER,
pass: process.env.EMAIL_PASS,
},
});

let badgeFilename;
if (badgeInfo.firstPR) {
badgeFilename = "PR1.png";
} else if (badgeInfo.secondOrThirdPR) {
badgeFilename = `PR${badgeInfo.prCount}.png`;
} else if (badgeInfo.fourthPR) {
badgeFilename = "PR4.png";
}

const badgeAttachment = {
filename: badgeFilename,
path: path.join(__dirname, `../badges/${badgeFilename}`),
};

await transporter.sendMail({
from: process.env.EMAIL_USER,
to: email,
subject: "Congratulations on your merged PR!",
text: message,
attachments: [badgeAttachment],
});
}

async function getUserEmail(username) {
try {
const { data: user } = await octokit.users.getByUsername({ username });
return user.email || null;
} catch (error) {
console.error(`Error fetching email for ${username}:`, error.message);
return null;
async function getUserEmail(username) {
try {
const { data: user } = await octokit.users.getByUsername({ username });
return user.email;
} catch (error) {
console.error(`Error fetching email for ${username}:`, error);
return null;
}
}
}

async function main() {
const pr = JSON.parse(
await fs.readFile(process.env.GITHUB_EVENT_PATH, "utf8")
);
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/badge-automation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
node-version: "16.x"

- name: Install dependencies
run: npm install @octokit/rest nodemailer
run: npm install nodemailer

- name: Run badge automation script
env:
Expand Down

0 comments on commit 102c0f9

Please sign in to comment.