Skip to content

Commit 5b26b87

Browse files
chore: prettify
1 parent 134350d commit 5b26b87

File tree

1 file changed

+79
-75
lines changed

1 file changed

+79
-75
lines changed

index.js

Lines changed: 79 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,145 +1,149 @@
1-
const core = require('@actions/core')
2-
const fs = require('fs')
3-
const path = require('path')
4-
const { spawn } = require('child_process')
5-
const { Toolkit } = require('actions-toolkit')
1+
const core = require("@actions/core");
2+
const fs = require("fs");
3+
const path = require("path");
4+
const { spawn } = require("child_process");
5+
const { Toolkit } = require("actions-toolkit");
66

7-
const MAX_LINES = 5
7+
const MAX_LINES = 5;
88

9-
const capitalize = (str) => str.slice(0, 1).toUpperCase() + str.slice(1)
9+
const capitalize = (str) => str.slice(0, 1).toUpperCase() + str.slice(1);
1010

11-
const urlPrefix = 'https://github.com/'
11+
const urlPrefix = "https://github.com/";
1212

1313
const toUrlFormat = (item) => {
14-
if (typeof item === 'object') {
15-
return Object.hasOwnProperty.call(item.payload, 'issue')
14+
if (typeof item === "object") {
15+
return Object.hasOwnProperty.call(item.payload, "issue")
1616
? `[#${item.payload.issue.number}](${urlPrefix}/${item.repo.name}/issues/${item.payload.issue.number})`
17-
: `[#${item.payload.pull_request.number}](${urlPrefix}/${item.repo.name}/pull/${item.payload.pull_request.number})`
17+
: `[#${item.payload.pull_request.number}](${urlPrefix}/${item.repo.name}/pull/${item.payload.pull_request.number})`;
1818
}
19-
return `[${item}](${urlPrefix}/${item})`
20-
}
19+
return `[${item}](${urlPrefix}/${item})`;
20+
};
2121

2222
const exec = (cmd, args = []) =>
2323
new Promise((resolve, reject) => {
24-
console.log(`Started: ${cmd} ${args.join(' ')}`)
25-
const app = spawn(cmd, args, { stdio: 'inherit' })
26-
app.on('close', (code) => {
24+
console.log(`Started: ${cmd} ${args.join(" ")}`);
25+
const app = spawn(cmd, args, { stdio: "inherit" });
26+
app.on("close", (code) => {
2727
if (code !== 0) {
28-
err = new Error(`Invalid status code: ${code}`)
29-
err.code = code
30-
return reject(err)
28+
err = new Error(`Invalid status code: ${code}`);
29+
err.code = code;
30+
return reject(err);
3131
}
32-
return resolve(code)
33-
})
34-
app.on('error', reject)
35-
})
32+
return resolve(code);
33+
});
34+
app.on("error", reject);
35+
});
3636

3737
const commitFile = async () => {
38-
await exec('git', [
39-
'config',
40-
'--global',
41-
'user.email',
42-
43-
])
44-
await exec('git', ['config', '--global', 'user.name', 'readme-bot'])
45-
await exec('git', ['add', 'README.md'])
46-
await exec('git', ['commit', '-m', 'update'])
47-
await exec('git', ['push'])
48-
}
38+
await exec("git", [
39+
"config",
40+
"--global",
41+
"user.email",
42+
43+
]);
44+
await exec("git", ["config", "--global", "user.name", "readme-bot"]);
45+
await exec("git", ["add", "README.md"]);
46+
await exec("git", ["commit", "-m", "update"]);
47+
await exec("git", ["push"]);
48+
};
4949

5050
const serializers = {
5151
IssueCommentEvent: (item) => {
5252
return `🗣 Commented on ${toUrlFormat(item)} in ${toUrlFormat(
5353
item.repo.name
54-
)}`
54+
)}`;
5555
},
5656
IssuesEvent: (item) => {
5757
return `❗️ ${capitalize(item.payload.action)} issue ${toUrlFormat(
5858
item
59-
)} in ${toUrlFormat(item.repo.name)}`
59+
)} in ${toUrlFormat(item.repo.name)}`;
6060
},
6161
PullRequestEvent: (item) => {
62-
const emoji = item.payload.action === 'opened' ? '💪' : '❌'
62+
const emoji = item.payload.action === "opened" ? "💪" : "❌";
6363
const line = item.payload.pull_request.merged
64-
? '🎉 Merged'
65-
: `${emoji} ${capitalize(item.payload.action)}`
66-
return `${line} PR ${toUrlFormat(item)} in ${toUrlFormat(item.repo.name)}`
64+
? "🎉 Merged"
65+
: `${emoji} ${capitalize(item.payload.action)}`;
66+
return `${line} PR ${toUrlFormat(item)} in ${toUrlFormat(item.repo.name)}`;
6767
},
68-
}
68+
};
6969

7070
Toolkit.run(
7171
async (tools) => {
72-
const GH_USERNAME = core.getInput('USERNAME')
72+
const GH_USERNAME = core.getInput("USERNAME");
7373

7474
// Get the user's public events
75-
tools.log.debug(`Getting activity for ${GH_USERNAME}`)
75+
tools.log.debug(`Getting activity for ${GH_USERNAME}`);
7676
const events = await tools.github.activity.listPublicEventsForUser({
7777
username: GH_USERNAME,
7878
per_page: 100,
79-
})
79+
});
8080
tools.log.debug(
8181
`Activity for ${GH_USERNAME}, ${events.data.length} events found.`
82-
)
82+
);
8383

8484
const content = events.data
8585
// Filter out any boring activity
8686
.filter((event) => serializers.hasOwnProperty(event.type))
8787
// We only have five lines to work with
8888
.slice(0, MAX_LINES)
8989
// Call the serializer to construct a string
90-
.map((item) => serializers[item.type](item))
90+
.map((item) => serializers[item.type](item));
9191

92-
const readmeContent = fs.readFileSync('./README.md', 'utf-8').split('\n')
92+
const readmeContent = fs.readFileSync("./README.md", "utf-8").split("\n");
9393

9494
let startIdx = readmeContent.findIndex(
95-
(content) => content === '<!--START_SECTION:activity-->'
96-
)
95+
(content) => content === "<!--START_SECTION:activity-->"
96+
);
9797
if (
98-
readmeContent.includes('<!--START_SECTION:activity-->') &&
99-
!readmeContent.includes('<!--END_SECTION:activity-->')
98+
readmeContent.includes("<!--START_SECTION:activity-->") &&
99+
!readmeContent.includes("<!--END_SECTION:activity-->")
100100
) {
101-
startIdx++
101+
startIdx++;
102102
content.forEach((line, idx) =>
103103
readmeContent.splice(startIdx + idx, 0, `${idx + 1}. ${line}`)
104-
)
105-
readmeContent.splice(startIdx + content.length, 0, '<!--END_SECTION:activity-->')
106-
fs.writeFileSync('./README.md', readmeContent.join('\n'))
104+
);
105+
readmeContent.splice(
106+
startIdx + content.length,
107+
0,
108+
"<!--END_SECTION:activity-->"
109+
);
110+
fs.writeFileSync("./README.md", readmeContent.join("\n"));
107111
try {
108-
await commitFile()
112+
await commitFile();
109113
} catch (err) {
110-
tools.log.debug('Something went wrong')
111-
return tools.exit.failure(err)
114+
tools.log.debug("Something went wrong");
115+
return tools.exit.failure(err);
112116
}
113-
tools.exit.success('Created initial setup')
117+
tools.exit.success("Created initial setup");
114118
}
115119

116120
const endIdx = readmeContent.findIndex(
117-
(content) => content === '<!--END_SECTION:activity-->'
118-
)
119-
const oldContent = readmeContent.slice(startIdx + 1, endIdx).join('\n')
120-
console.log()
121+
(content) => content === "<!--END_SECTION:activity-->"
122+
);
123+
const oldContent = readmeContent.slice(startIdx + 1, endIdx).join("\n");
124+
console.log();
121125
const newContent = content
122126
.map((line, idx) => `${idx + 1}. ${line}`)
123-
.join('\n')
127+
.join("\n");
124128

125129
if (oldContent.trim() === newContent.trim())
126-
tools.exit.success('No changes detected')
130+
tools.exit.success("No changes detected");
127131

128-
startIdx++
132+
startIdx++;
129133
content.forEach(
130134
(line, idx) => (readmeContent[startIdx + idx] = `${idx + 1}. ${line}`)
131-
)
132-
fs.writeFileSync('./README.md', readmeContent.join('\n'))
135+
);
136+
fs.writeFileSync("./README.md", readmeContent.join("\n"));
133137
try {
134-
await commitFile()
138+
await commitFile();
135139
} catch (err) {
136-
tools.log.debug('Something went wrong')
137-
return tools.exit.failure(err)
140+
tools.log.debug("Something went wrong");
141+
return tools.exit.failure(err);
138142
}
139-
tools.exit.success('Updated ')
143+
tools.exit.success("Updated ");
140144
},
141145
{
142-
event: 'schedule',
143-
secrets: ['GITHUB_TOKEN'],
146+
event: "schedule",
147+
secrets: ["GITHUB_TOKEN"],
144148
}
145-
)
149+
);

0 commit comments

Comments
 (0)