Skip to content

Commit 8f02e45

Browse files
committed
feat: update worklow details
1 parent 67e6b68 commit 8f02e45

File tree

4 files changed

+105
-12
lines changed

4 files changed

+105
-12
lines changed

scripts/src/fetchFollowers.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ if(process.env.ACCESS_TOKEN === undefined){
88

99
import { Octokit } from "@octokit/rest";
1010
import { readFileSync, writeFileSync } from "fs";
11-
import { updateWorkflowNumber } from "./updateWorkflowNumber.js";
11+
import { updateWorkflowNumber } from "./updateWorkflow.js";
1212
import { READMEFILE_PATH } from "./config.js";
1313

1414
const octokit = new Octokit({

scripts/src/fetchLatestBlogPosts.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ dotenv.config();
33

44
import axios from "axios";
55
import { readFileSync, writeFileSync } from "fs";
6-
import { updateWorkflowNumber } from "./updateWorkflowNumber.js";
6+
import { updateWorkflowNumber } from "./updateWorkflow.js";
77
import { BlogsResponseSchema, READMEFILE_PATH } from "./config.js";
88

99
const fetchLatestBlogs = async () => {

scripts/src/langGraph.js

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import dotenv from "dotenv";
2+
dotenv.config();
3+
4+
if (process.env.ACCESS_TOKEN === undefined) {
5+
console.error("Please provide ACCESS_TOKEN in .env file");
6+
process.exit(1);
7+
}
8+
9+
import { Octokit } from "@octokit/rest";
10+
import axios from "axios";
11+
import fs from "fs";
12+
13+
async function getAllRepositories(octokit) {
14+
try {
15+
const repos = await octokit.paginate(
16+
octokit.repos.listForAuthenticatedUser,
17+
{
18+
per_page: 100,
19+
affiliation: "owner",
20+
sort: "updated",
21+
direction: "desc",
22+
}
23+
);
24+
25+
const nonForkedRepos = repos.filter((repo) => !repo.fork);
26+
console.log(`Fetched ${nonForkedRepos.length} non-forked repositories`);
27+
return nonForkedRepos;
28+
} catch (error) {
29+
console.log(`Error fetching repositories: ${error.message}`);
30+
throw error;
31+
}
32+
}
33+
34+
async function getLanguageStats(octokit, repos) {
35+
const languageStats = {};
36+
37+
for (const repo of repos) {
38+
try {
39+
const languages = await octokit.repos.listLanguages({
40+
owner: repo.owner.login,
41+
repo: repo.name,
42+
});
43+
44+
for (const [language, bytes] of Object.entries(languages.data)) {
45+
languageStats[language] = (languageStats[language] || 0) + bytes;
46+
}
47+
console.log(`Processed languages for ${repo.name}`);
48+
} catch (error) {
49+
console.log(
50+
`Error fetching languages for ${repo.name}: ${error.message}`
51+
);
52+
}
53+
}
54+
55+
return languageStats;
56+
}
57+
58+
async function main() {
59+
try {
60+
if (!process.env.ACCESS_TOKEN) {
61+
throw new Error(
62+
"GitHub token not found. Please set ACCESS_TOKEN in .env file."
63+
);
64+
}
65+
66+
const octokit = new Octokit({ auth: process.env.ACCESS_TOKEN });
67+
68+
console.log("Starting repository and language analysis...");
69+
70+
const repos = await getAllRepositories(octokit);
71+
const languageStats = await getLanguageStats(octokit, repos);
72+
73+
console.log(languageStats);
74+
75+
console.log("Analysis completed successfully!");
76+
} catch (error) {
77+
console.log(`Fatal error: ${error.message}`);
78+
process.exit(1);
79+
}
80+
}
81+
82+
main();

scripts/src/updateWorkflowNumber.js renamed to scripts/src/updateWorkflow.js

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,33 +14,44 @@ const octokit = new Octokit({
1414
auth: process.env.ACCESS_TOKEN,
1515
});
1616

17-
const getWorflowCount = async () => {
17+
const getLatestWorkflow = async () => {
1818
const username = "pulkitxm";
1919
const repoName = username;
2020
try {
2121
const response = await octokit.actions.listWorkflowRunsForRepo({
2222
owner: username,
2323
repo: repoName,
2424
});
25-
return response.data.total_count;
25+
return {
26+
count: response.data.total_count,
27+
timeStamp: response.data.workflow_runs[0].created_at,
28+
};
2629
} catch (error) {
2730
console.error(error.message);
28-
return 0;
31+
return {
32+
count: 0,
33+
timeStamp: new Date().toISOString(),
34+
};
2935
}
3036
};
3137

3238
export async function updateWorkflowNumber() {
33-
const workflowCount = await getWorflowCount();
39+
const workflowDetails = await getLatestWorkflow();
40+
const count = workflowDetails.count;
41+
const timeStamp = new Date(workflowDetails.timeStamp);
42+
3443
const readmeContent = readFileSync(READMEFILE_PATH, "utf-8");
3544

36-
// *Note: All the data displayed above is updated automatically via GitHub Actions. There have been **3** workflow runs so far.*
3745
const updatedContent = readmeContent.replace(
38-
/Note: All the data displayed above is updated automatically via GitHub Actions. There have been \*\*\d+\*\* workflow runs so far./,
39-
`Note: All the data displayed above is updated automatically via GitHub Actions. There have been **${workflowCount}** workflow runs so far.`
46+
/(?<=<!--START_SECTION:workflows-update-->\n)[\s\S]*(?=\n<!--END_SECTION:workflows-update-->)/,
47+
`\n<p align="center">
48+
This <i>README</i> file is refreshed <b>every 24 hours</b>!<br/>
49+
Last refresh: <b>${timeStamp.toUTCString().split(",")[1]}</b><br/>
50+
Number of workflows: ${count}<br/><br/>
51+
Made with ❤️ by Pulkit
52+
</p>\n`
4053
);
4154

4255
writeFileSync(READMEFILE_PATH, updatedContent, "utf-8");
43-
console.log(
44-
`README file updated with the latest workflow count(${workflowCount}).`
45-
);
56+
console.log(`README file updated with the latest workflow count(${count}).`);
4657
}

0 commit comments

Comments
 (0)