@@ -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,30 @@ 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 SARIF (Static Analysis Results Interchange Format) file to GitHub's code scanning API.
110
+ * This method handles the communication with GitHub's REST API to populate the code scanning tab with security analysis results.
111
+ * Supports both GitHub.com and GitHub Enterprise Server installations.
112
+ * @param encodedSarif - The SARIF content that has been compressed using gzip and encoded to base64 format.
113
+ * This encoding is required by GitHub's code-scanning/sarifs API endpoint.
114
+ * @param token - GitHub authentication token with appropriate permissions to upload SARIF files.
115
+ * Must have 'security_events: write' and 'contents: read' permissions.
116
+ * @throws Will throw an error if the HTTP response status is not in the 2xx range or if authentication fails.
114
117
*/
115
118
static uploadCodeScanningSarif ( encodedSarif , token ) {
116
119
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' , {
120
+ var _a , _b , _c ;
121
+ const inputBaseUrl = core . getInput ( 'ghe-base-url' , { required : false } ) || core . getInput ( 'ghe_base_url' , { required : false } ) || '' ;
122
+ const octokit = inputBaseUrl ? github . getOctokit ( token , { baseUrl : inputBaseUrl } ) : github . getOctokit ( token ) ;
123
+ const response = yield octokit . request ( 'POST /repos/{owner}/{repo}/code-scanning/sarifs' , {
120
124
owner : github . context . repo . owner ,
121
125
repo : github . context . repo . repo ,
122
126
commit_sha : github . context . sha ,
123
127
ref : github . context . ref ,
124
128
sarif : encodedSarif ,
125
129
} ) ;
126
130
if ( response . status < 200 || response . status >= 300 ) {
127
- throw new Error ( `Failed to upload SARIF file: ` + JSON . stringify ( response ) ) ;
131
+ 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' ;
132
+ throw new Error ( `Failed to upload SARIF file (status ${ response . status } ). baseUrl=${ usedBaseUrl } ; response=` + JSON . stringify ( response ) ) ;
128
133
}
129
134
core . info ( 'SARIF file uploaded successfully' ) ;
130
135
} ) ;
0 commit comments