Skip to content

Commit 3dfac4f

Browse files
committed
updated the files
1 parent 0b510fb commit 3dfac4f

File tree

4 files changed

+181
-1
lines changed

4 files changed

+181
-1
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
.env

automate.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
const axios = require('axios');
2+
3+
const GITHUB_TOKEN = process.env.GITHUB_TOKEN;
4+
const REPO_OWNER = process.env.REPO_OWNER;
5+
const REPO_NAME = process.env.REPO_NAME;
6+
7+
const triggerWorkflow = async () => {
8+
try {
9+
const response = await axios.post(
10+
`https://api.github.com/repos/${REPO_OWNER}/${REPO_NAME}/actions/workflows/ci-cd-pipeline.yml/dispatches`,
11+
{ ref: 'main' },
12+
{
13+
headers: {
14+
'Authorization': `token ${GITHUB_TOKEN}`,
15+
'Accept': 'application/vnd.github.v3+json'
16+
}
17+
}
18+
);
19+
console.log('Workflow triggered successfully:', response.data);
20+
} catch (error) {
21+
console.error('Error triggering workflow:', error.response.data);
22+
}
23+
};
24+
25+
const checkWorkflowRuns = async () => {
26+
try {
27+
const response = await axios.get(
28+
`https://api.github.com/repos/${REPO_OWNER}/${REPO_NAME}/actions/runs`,
29+
{
30+
headers: {
31+
'Authorization': `token ${GITHUB_TOKEN}`,
32+
'Accept': 'application/vnd.github.v3+json'
33+
}
34+
}
35+
);
36+
console.log('Recent Workflow Runs:', response.data);
37+
} catch (error) {
38+
console.error('Error fetching workflow runs:', error.response.data);
39+
}
40+
};
41+
42+
// Example usage
43+
(async () => {
44+
await triggerWorkflow();
45+
await checkWorkflowRuns();
46+
})();

package-lock.json

Lines changed: 128 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,9 @@
88
},
99
"keywords": [],
1010
"author": "Aman Chopra",
11-
"license": "ISC"
11+
"license": "ISC",
12+
"dependencies": {
13+
"axios": "^1.7.7",
14+
"dotenv": "^16.4.5"
15+
}
1216
}

0 commit comments

Comments
 (0)