Skip to content

Commit b0cb5a4

Browse files
Merge pull request #6 from Contrast-Security-OSS/PRODSEC-462
Prodsec 462 - fix policyUrl context
2 parents 8b743c9 + fbf3a9f commit b0cb5a4

File tree

4 files changed

+23
-19
lines changed

4 files changed

+23
-19
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,14 @@ All notable changes to this project will be documented in this file. Dates are d
44

55
Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
66

7+
#### [v1.0.4](https://github.com/Contrast-Security-OSS/actionbot/compare/v1.0.3...v1.0.4)
8+
9+
- fix: policyUrl getContents was using context owner and repo [`71e65a3`](https://github.com/Contrast-Security-OSS/actionbot/commit/71e65a36efa30aff6fc8c7e53abdb462131bf2f3)
10+
711
#### [v1.0.3](https://github.com/Contrast-Security-OSS/actionbot/compare/v1.0.0...v1.0.3)
812

13+
> 1 May 2025
14+
915
- Bump eslint-plugin-github from 5.1.8 to 6.0.0 [`#1`](https://github.com/Contrast-Security-OSS/actionbot/pull/1)
1016
- Migration build [`#3`](https://github.com/Contrast-Security-OSS/actionbot/pull/3)
1117
- Migrate @actions/github from 4.0.0 to 6.0.0 [`#2`](https://github.com/Contrast-Security-OSS/actionbot/pull/2)

lib/index.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39024,16 +39024,15 @@ function run(context) {
3902439024
});
3902539025
}
3902639026
else {
39027-
// Correctly extract the file path from the policyUrl
39028-
const filePath = policyUrl
39029-
.replace("https://github.com/", "")
39030-
.split("/")
39031-
.slice(4) // Start after 'blob/main'
39032-
.join("/");
39027+
// Extract owner, repo, and file path from the policyUrl
39028+
const urlParts = policyUrl.replace("https://github.com/", "").split("/");
39029+
const owner = urlParts[0]; // Extract the owner
39030+
const repo = urlParts[1]; // Extract the repository name
39031+
const filePath = urlParts.slice(4).join("/"); // Extract the file path after 'blob/{branch}'
3903339032
const response = yield client.rest.repos.getContent({
39034-
owner: github.context.repo.owner,
39035-
repo: github.context.repo.repo,
39036-
path: filePath, // Use the corrected file path
39033+
owner: owner, // Use the extracted owner
39034+
repo: repo, // Use the extracted repo
39035+
path: filePath, // Use the extracted file path
3903739036
});
3903839037
if (response.data && "content" in response.data) {
3903939038
const content = Buffer.from(response.data.content, "base64").toString("utf-8");

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "actionbot",
3-
"version": "1.0.3",
3+
"version": "1.0.4",
44
"private": true,
55
"description": "Github Action Policy Checker as a Github Action",
66
"main": "lib/index.js",

src/main.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -171,17 +171,16 @@ async function run(context: typeof github.context): Promise<void> {
171171
// Handle the error appropriately (e.g., throw an error, set a default policy)
172172
});
173173
} else {
174-
// Correctly extract the file path from the policyUrl
175-
const filePath = policyUrl
176-
.replace("https://github.com/", "")
177-
.split("/")
178-
.slice(4) // Start after 'blob/main'
179-
.join("/");
174+
// Extract owner, repo, and file path from the policyUrl
175+
const urlParts = policyUrl.replace("https://github.com/", "").split("/");
176+
const owner = urlParts[0]; // Extract the owner
177+
const repo = urlParts[1]; // Extract the repository name
178+
const filePath = urlParts.slice(4).join("/"); // Extract the file path after 'blob/{branch}'
180179

181180
const response = await client.rest.repos.getContent({
182-
owner: github.context.repo.owner,
183-
repo: github.context.repo.repo,
184-
path: filePath, // Use the corrected file path
181+
owner: owner, // Use the extracted owner
182+
repo: repo, // Use the extracted repo
183+
path: filePath, // Use the extracted file path
185184
});
186185

187186
if (response.data && "content" in response.data) {

0 commit comments

Comments
 (0)