Skip to content

Commit 018b5b7

Browse files
committed
feat: update worklow details
1 parent 67e6b68 commit 018b5b7

File tree

5 files changed

+158
-60
lines changed

5 files changed

+158
-60
lines changed

.github/workflows/update-readme.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ jobs:
1616
- name: Update Blog Posts
1717
run: |
1818
cd scripts && npm install && ACCESS_TOKEN=${{ secrets.ACCESS_TOKEN }} npm run get:posts
19+
- name: Update Language Graph
20+
run: |
21+
cd scripts && npm install && ACCESS_TOKEN=${{ secrets.ACCESS_TOKEN }} npm run get:langGraph
1922
- name: Commit changes
2023
run: |
2124
git config --local user.email "github-actions[bot]@users.noreply.github.com"

README.md

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -109,25 +109,24 @@
109109

110110
---
111111

112+
<br/>
113+
112114
<picture>
113115
<source media="(prefers-color-scheme: dark)" srcset="https://wakatime.com/share/@pulkitxm/b09efaa2-860c-4ed4-afbe-4a645828d6fe.svg">
114-
<img src="https://wakatime.com/share/@pulkitxm/b09efaa2-860c-4ed4-afbe-4a645828d6fe.svg" width="100%" height="auto" style="max-height: 400px; object-fit: contain;">
116+
<img src="https://wakatime.com/share/@pulkitxm/b09efaa2-860c-4ed4-afbe-4a645828d6fe.svg" width="100%" height="auto">
115117
</picture>
116118

117-
<br/><br/>
118-
119-
---
120-
121-
### Let's Connect
122-
123-
- [LinkedIn](https://www.linkedin.com/in/pulkitxm)
124-
- [Twitter](https://x.com/devpulkitt)
125-
- [Email](mailto:[email protected])
119+
<br/>
126120

127-
---
121+
------------
128122

129-
<!--START_SECTION:workflows-->
123+
<!--START_SECTION:workflows-update-->
130124

131-
_Note: All the data displayed above is updated automatically via GitHub Actions. There have been **20** workflow runs so far._
125+
<br/><p align="center">
126+
This <i>README</i> file is refreshed <b>every 24 hours</b>!<br/>
127+
Last refresh: <b> </b><br/>
128+
Number of workflows: <br/><br/>
129+
Made with ❤️ by Pulkit
130+
</p>
132131

133-
<!--END_SECTION:workflows-->
132+
<!--END_SECTION:workflows-update-->

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/updateWorkflow.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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 { readFileSync, writeFileSync } from "fs";
11+
import { READMEFILE_PATH } from "./config.js";
12+
13+
const octokit = new Octokit({
14+
auth: process.env.ACCESS_TOKEN,
15+
});
16+
17+
const getLatestWorkflow = async () => {
18+
const username = "pulkitxm";
19+
const repoName = username;
20+
try {
21+
const response = await octokit.actions.listWorkflowRunsForRepo({
22+
owner: username,
23+
repo: repoName,
24+
});
25+
return {
26+
count: response.data.total_count,
27+
timeStamp: response.data.workflow_runs[0].created_at,
28+
};
29+
} catch (error) {
30+
console.error(error.message);
31+
return {
32+
count: 0,
33+
timeStamp: new Date().toISOString(),
34+
};
35+
}
36+
};
37+
38+
export async function updateWorkflowNumber() {
39+
const workflowDetails = await getLatestWorkflow();
40+
const count = workflowDetails.count;
41+
const timeStamp = new Date(workflowDetails.timeStamp);
42+
43+
const readmeContent = readFileSync(READMEFILE_PATH, "utf-8");
44+
45+
const updatedContent = readmeContent.replace(
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`
53+
);
54+
55+
writeFileSync(READMEFILE_PATH, updatedContent, "utf-8");
56+
console.log(`README file updated with the latest workflow count(${count}).`);
57+
}
58+
59+
export async function lastUpdated() {}
60+
updateWorkflowNumber();

scripts/src/updateWorkflowNumber.js

Lines changed: 0 additions & 46 deletions
This file was deleted.

0 commit comments

Comments
 (0)