@@ -38,7 +38,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
38
38
exports . JobSummary = void 0 ;
39
39
const core = __importStar ( require ( "@actions/core" ) ) ;
40
40
const semver_1 = require ( "semver" ) ;
41
- const core_1 = require ( "@octokit/core" ) ;
42
41
const github = __importStar ( require ( "@actions/github" ) ) ;
43
42
const util_1 = require ( "util" ) ;
44
43
const zlib_1 = require ( "zlib" ) ;
@@ -107,24 +106,38 @@ class JobSummary {
107
106
} ) ;
108
107
}
109
108
/**
110
- * Uploads the code scanning SARIF content to the code-scanning GitHub API.
111
- * @param encodedSarif - The final compressed and encoded sarif content.
112
- * @param token - GitHub token to use for the request. Has to have 'security-events: write' permission.
113
- * @private
109
+ * Uploads a gzip-compressed, base64-encoded SARIF payload to GitHub Code Scanning.
110
+ *
111
+ * Uses the current GitHub Actions context (owner, repo, commit SHA, and ref) for the target.
112
+ * If a GitHub Enterprise Server base URL is provided via the 'ghe-base-url' or 'ghe_base_url'
113
+ * action input, the request is sent to that endpoint; otherwise, it targets github.com.
114
+ *
115
+ * @param encodedSarif - The SARIF report content after gzip compression and base64 encoding,
116
+ * as required by the POST /repos/{owner}/{repo}/code-scanning/sarifs API.
117
+ * Typically produced by compressing raw SARIF with gzip and encoding to base64.
118
+ * @param token - GitHub token used to authenticate the upload request. Must have
119
+ * security_events: write permission on the target repository (e.g., a PAT or GITHUB_TOKEN
120
+ * with the appropriate permission).
121
+ *
122
+ * @returns A promise that resolves when the upload completes successfully.
123
+ * @throws Error if the API response status is not 2xx; the thrown error includes the resolved baseUrl
124
+ * and a serialized response summary to aid debugging.
114
125
*/
115
126
static uploadCodeScanningSarif ( encodedSarif , token ) {
116
127
return __awaiter ( this , void 0 , void 0 , function * ( ) {
117
- const octokit = new core_1 . Octokit ( { auth : token } ) ;
118
- let response ;
119
- response = yield octokit . request ( 'POST /repos/{owner}/{repo}/code-scanning/sarifs' , {
128
+ var _a , _b , _c ;
129
+ const inputBaseUrl = core . getInput ( 'ghe-base-url' , { required : false } ) || core . getInput ( 'ghe_base_url' , { required : false } ) || '' ;
130
+ const octokit = inputBaseUrl ? github . getOctokit ( token , { baseUrl : inputBaseUrl } ) : github . getOctokit ( token ) ;
131
+ const response = yield octokit . request ( 'POST /repos/{owner}/{repo}/code-scanning/sarifs' , {
120
132
owner : github . context . repo . owner ,
121
133
repo : github . context . repo . repo ,
122
134
commit_sha : github . context . sha ,
123
135
ref : github . context . ref ,
124
136
sarif : encodedSarif ,
125
137
} ) ;
126
138
if ( response . status < 200 || response . status >= 300 ) {
127
- throw new Error ( `Failed to upload SARIF file: ` + JSON . stringify ( response ) ) ;
139
+ const usedBaseUrl = ( ( _c = ( _b = ( _a = octokit . request ) === null || _a === void 0 ? void 0 : _a . endpoint ) === null || _b === void 0 ? void 0 : _b . DEFAULTS ) === null || _c === void 0 ? void 0 : _c . baseUrl ) || 'unknown' ;
140
+ throw new Error ( `Failed to upload SARIF file (status ${ response . status } ). baseUrl=${ usedBaseUrl } ; response=` + JSON . stringify ( response ) ) ;
128
141
}
129
142
core . info ( 'SARIF file uploaded successfully' ) ;
130
143
} ) ;
0 commit comments