@@ -2,7 +2,6 @@ import _ from 'lodash';
2
2
import childProcess from 'child_process' ;
3
3
import $RefParser from "@apidevtools/json-schema-ref-parser" ;
4
4
import fs from 'fs-extra' ;
5
- import githubApi from "github-api-promise" ;
6
5
import https from 'https' ;
7
6
import path from 'path' ;
8
7
import pluralize from 'pluralize' ;
@@ -18,6 +17,8 @@ import GitModule from '../git/gitModule';
18
17
import Zip from '../util/zip' ;
19
18
import { Models } from 'purecloud-platform-client-v2' ;
20
19
import log from '../log/logger' ;
20
+ import axios from "axios" ;
21
+ import { Endpoints } from "@octokit/types" ;
21
22
22
23
23
24
const swaggerDiff = new SwaggerDiff ( ) ;
@@ -183,7 +184,7 @@ export class Builder {
183
184
const commonRoot = path . resolve ( './' ) ;
184
185
const sdkRepo = path . resolve ( path . join ( './output' , this . config . settings . swaggerCodegen . codegenLanguage ) ) ;
185
186
const sdkTemp = path . resolve ( path . join ( './temp' , this . config . settings . swaggerCodegen . codegenLanguage ) ) ;
186
-
187
+
187
188
log . debug ( `Environment paths - CommonRoot: ${ commonRoot } , SdkRepo: ${ sdkRepo } , SdkTemp: ${ sdkTemp } ` ) ;
188
189
setEnv ( 'COMMON_ROOT' , commonRoot ) ;
189
190
setEnv ( 'SDK_REPO' , sdkRepo ) ;
@@ -741,9 +742,9 @@ function createRelease(): Promise<string> {
741
742
log . log . debug ( `repoName: ${ repoName } ` ) ;
742
743
log . log . debug ( `repoOwner: ${ repoOwner } ` ) ;
743
744
744
- githubApi . config . repo = repoName ;
745
- githubApi . config . owner = repoOwner ;
746
- githubApi . config . token = getEnv ( 'GITHUB_TOKEN' ) as string ;
745
+ githubConfig . repo = repoName ;
746
+ githubConfig . owner = repoOwner ;
747
+ githubConfig . token = getEnv ( 'GITHUB_TOKEN' ) as string ;
747
748
748
749
const tagName = _this . config . settings . sdkRepo . tagFormat . replace ( '{version}' , _this . version . displayFull ) ;
749
750
let createReleaseOptions = {
@@ -757,7 +758,7 @@ function createRelease(): Promise<string> {
757
758
758
759
console . log ( createReleaseOptions ) ;
759
760
// Create release
760
- return githubApi . repos . releases . createRelease ( createReleaseOptions ) ;
761
+ return githubCreateRelease ( createReleaseOptions ) ;
761
762
} )
762
763
. then ( ( release ) => {
763
764
log . info ( `Created release #${ release } ` ) ;
@@ -1240,4 +1241,93 @@ function getFileCount(dir: fs.PathLike) {
1240
1241
}
1241
1242
1242
1243
return files . length ;
1243
- }
1244
+ }
1245
+
1246
+ // Alternative to github-api-promise until update
1247
+
1248
+ let githubConfig : any = {
1249
+ owner : "github_username" ,
1250
+ repo : "repo_name" ,
1251
+ token : "your_github_token" ,
1252
+ host : "https://api.github.com" ,
1253
+ debug : false ,
1254
+ } ;
1255
+
1256
+ function githubGetRepoUrl ( additionalPath : string ) {
1257
+ var url = githubConfig . host + "/repos/" + githubConfig . owner + "/" + githubConfig . repo + "/" ;
1258
+ if ( additionalPath ) url += additionalPath ;
1259
+ return url ;
1260
+ }
1261
+
1262
+ function githubLogRequestSuccess ( res : any , message ?: string ) {
1263
+ if ( githubConfig . debug != true ) {
1264
+ return ;
1265
+ }
1266
+ let logMsg : string = "[INFO]" +
1267
+ "[" +
1268
+ res . statusCode +
1269
+ "]" +
1270
+ "[" +
1271
+ res . req . method +
1272
+ " " +
1273
+ res . req . path +
1274
+ "] " +
1275
+ ( message ? message : "" ) ;
1276
+
1277
+ console . log ( logMsg ) ;
1278
+ }
1279
+
1280
+ function githubLogRequestError ( err : any ) {
1281
+ if ( err ) {
1282
+ let logMsg : string = "[ERROR]" +
1283
+ "[" +
1284
+ ( err . res ? err . res . statusCode : "Unknown Status Code" ) +
1285
+ "]" +
1286
+ "[" +
1287
+ ( err . res && err . res . req ? err . res . req . method : "Unknown Method" ) +
1288
+ " " +
1289
+ ( err . res && err . res . req ? err . res . req . path : "Unknown Path" ) +
1290
+ "] " +
1291
+ ( err . message ? err . message : "Unknown Error Message" ) ;
1292
+ console . log ( logMsg ) ;
1293
+ } else {
1294
+ console . log ( "[ERROR] Unknown Error" ) ;
1295
+ }
1296
+ }
1297
+
1298
+ /**
1299
+ * Users with push access to the repository can create a release. Returns 422 if anything is wrong with the values in the body.
1300
+ * @param {JSON } body A JSON document to send with the request
1301
+ * @return {JSON } The release data
1302
+ */
1303
+ function githubCreateRelease (
1304
+ body : any
1305
+ ) : Promise <
1306
+ Endpoints [ "POST /repos/{owner}/{repo}/releases" ] [ "response" ] [ "data" ]
1307
+ > {
1308
+ return new Promise ( ( resolve , reject ) => {
1309
+ try {
1310
+ axios
1311
+ . post ( githubGetRepoUrl ( "releases" ) , body , {
1312
+ headers : {
1313
+ Authorization : `token ${ githubConfig . token } ` ,
1314
+ "User-Agent" : "github-api-promise" ,
1315
+ "Content-Type" : "application/json" ,
1316
+ } ,
1317
+ } )
1318
+ . then (
1319
+ function ( res : any ) {
1320
+ githubLogRequestSuccess ( res ) ;
1321
+ resolve ( res . body ) ;
1322
+ } ,
1323
+ function ( err : any ) {
1324
+ githubLogRequestError ( err ) ;
1325
+ reject ( err . message ) ;
1326
+ }
1327
+ ) ;
1328
+ } catch ( err ) {
1329
+ console . log ( err ) ;
1330
+ reject ( err . message ) ;
1331
+ }
1332
+ } ) ;
1333
+ }
0 commit comments