From 2ca4a36e5756da6e61b4bde725570c633d9f4352 Mon Sep 17 00:00:00 2001 From: Jochen Ulrich Date: Thu, 9 Jul 2020 04:13:42 +0200 Subject: [PATCH 01/36] Excludes .github files from .gitignore and adds npm files --- .gitignore | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index edacf2c..10843f5 100644 --- a/.gitignore +++ b/.gitignore @@ -2,8 +2,12 @@ !.gitignore !.appveyor.yml !.travis.yml +!.github build/ .build/ _build/ build_*/ -CMakeLists.txt.user \ No newline at end of file +CMakeLists.txt.user +package.json +package-lock.json +node_modules/ \ No newline at end of file From b99c1262597dc3d35684403ce070dc12a22f4c22 Mon Sep 17 00:00:00 2001 From: Jochen Ulrich Date: Thu, 9 Jul 2020 04:14:11 +0200 Subject: [PATCH 02/36] Adds scripts to check for HTTP status codes updates --- .github/checkForHttpStatusCodesUpdate.js | 106 +++++++++++++++++++++ .github/http-status-codes.txt | 111 ++++++++++++++++++++++ .github/workflows/checkForCodeUpdates.yml | 19 ++++ 3 files changed, 236 insertions(+) create mode 100644 .github/checkForHttpStatusCodesUpdate.js create mode 100644 .github/http-status-codes.txt create mode 100644 .github/workflows/checkForCodeUpdates.yml diff --git a/.github/checkForHttpStatusCodesUpdate.js b/.github/checkForHttpStatusCodesUpdate.js new file mode 100644 index 0000000..fe494fa --- /dev/null +++ b/.github/checkForHttpStatusCodesUpdate.js @@ -0,0 +1,106 @@ +const fetch = require( 'node-fetch' ); +const diff = require( 'diff' ); +const fs = require( 'fs/promises' ); +const path = require( 'path' ); + + +const httpStatusCodesUrl = 'https://www.iana.org/assignments/http-status-codes/http-status-codes.txt'; + +const checkForUpdate = async ( { github, core } ) => { + try + { + const httpStatusCodes = await fetchHttpStatusCodesList(); + const diffWithLastUsedVersion = await getDiffWithLastUsedVersion( httpStatusCodes.httpStatusCodesList ); + if ( !diffWithLastUsedVersion ) { + return; + } + const existingGithubIssues = await searchForExistingGithubIssue( httpStatusCodes.lastUpdated, github ); + + if ( existingGithubIssues.total_count === 0 ) { + const newIssue = await createNewGithubIssue( httpStatusCodes, diffWithLastUsedVersion, github ); + core.info( `Created issue #${newIssue.number}: ${newIssue.html_url}`); + } + else if ( existingGithubIssues.total_count === 1 ) { + core.info( 'HTTP status codes are still up to date.' ); + } + else { + core.warning( `Multiple issues exist for the HTTP status code update from ${httpStatusCodes.lastUpdated}` ); + } + } + catch ( error ) { + core.setFailed( `Could not check for HTTP status codes updates: ${error}` ); + throw error; + } +}; + +const fetchHttpStatusCodesList = async () => { + const response = await fetch( httpStatusCodesUrl ); + if ( !response.ok ) { + throw Error( `Error fetching HTTP status codes list: ${response.status} ${response.statusText}` ); + } + const httpStatusCodesList = await response.text(); + + const match = /Last Updated\s+(\d{4}-\d{2}-\d{2})/.exec( httpStatusCodesList ); + if ( !match ) { + throw Error( 'Could not find "Last Updated" date in HTTP status list' ); + } + const lastUpdated = match[ 1 ]; + return { lastUpdated, httpStatusCodesList }; +}; + +const issueTitleBase = 'IANA HTTP Status Code Update'; + +const searchForExistingGithubIssue = async ( lastUpdatedDate, github ) => { + const query = [ issueTitleBase, lastUpdatedDate, 'in:title', 'repo:j-ulrich/http-status-codes-cpp', 'type:issue' ].join( '+' ); + const searchResult = await github.search.issuesAndPullRequests( { + q: query, + } ); + return searchResult; +}; + +const createNewGithubIssue = async ( httpStatusCodes, diffWithLastUsedVersion, github ) => { + + return github.issues.create( { + owner: 'j-ulrich', + repo: 'http-status-codes-cpp', + title: `${issueTitleBase} ${httpStatusCodes.lastUpdatedDate}`, + body: `The HTTP status codes list has been updated on ${httpStatusCodes.lastUpdatedDate}.` + '\n' + + 'See https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml' + '\n\n' + + '## Diff ##' + '\n' + + '```diff' + '\n' + + diffWithLastUsedVersion + '\n' + + '```' + } ); +}; + +const getDiffWithLastUsedVersion = async ( httpStatusCodeList ) => { + const pathToLastUsedVersion = path.resolve( './.github/http-status-codes.txt' ); + const lastUsedVersion = await fs.readFile( pathToLastUsedVersion, { encoding: 'utf-8' } ); + if ( lastUsedVersion === httpStatusCodeList ) { + return null; + } + const patch = diff.createPatch( 'http-status-codes.txt', lastUsedVersion, httpStatusCodeList ); + return patch; +}; + +const main = async () => { + try + { + const httpStatusCodes = await fetchHttpStatusCodesList(); + console.log( httpStatusCodes.lastUpdated ); + const patch = await getDiffWithLastUsedVersion( httpStatusCodes.httpStatusCodesList ); + if ( patch ) { + console.log( patch ); + } + } + catch( reason ) { + console.error( reason ); + process.exitCode = -1; + }; +}; + +module.exports = checkForUpdate; + +if ( require.main === module ) { + main(); +} \ No newline at end of file diff --git a/.github/http-status-codes.txt b/.github/http-status-codes.txt new file mode 100644 index 0000000..09d4264 --- /dev/null +++ b/.github/http-status-codes.txt @@ -0,0 +1,111 @@ + Hypertext Transfer Protocol (HTTP) Status Code Registry + + Last Updated + 2018-09-21 + + Available Formats + [IMG] + XML [IMG] + HTML [IMG] + Plain text + + Registry included below + + * HTTP Status Codes + +HTTP Status Codes + + Registration Procedure(s) + + IETF Review + + Reference + [RFC7231] + + Note + + 1xx: Informational - Request received, continuing process + 2xx: Success - The action was successfully received, understood, and accepted + 3xx: Redirection - Further action must be taken in order to complete the request + 4xx: Client Error - The request contains bad syntax or cannot be fulfilled + 5xx: Server Error - The server failed to fulfill an apparently valid request + + + Available Formats + [IMG] + CSV + + Value Description Reference + 100 Continue [RFC7231, Section 6.2.1] + 101 Switching Protocols [RFC7231, Section 6.2.2] + 102 Processing [RFC2518] + 103 Early Hints [RFC8297] + 104-199 Unassigned + 200 OK [RFC7231, Section 6.3.1] + 201 Created [RFC7231, Section 6.3.2] + 202 Accepted [RFC7231, Section 6.3.3] + 203 Non-Authoritative Information [RFC7231, Section 6.3.4] + 204 No Content [RFC7231, Section 6.3.5] + 205 Reset Content [RFC7231, Section 6.3.6] + 206 Partial Content [RFC7233, Section 4.1] + 207 Multi-Status [RFC4918] + 208 Already Reported [RFC5842] + 209-225 Unassigned + 226 IM Used [RFC3229] + 227-299 Unassigned + 300 Multiple Choices [RFC7231, Section 6.4.1] + 301 Moved Permanently [RFC7231, Section 6.4.2] + 302 Found [RFC7231, Section 6.4.3] + 303 See Other [RFC7231, Section 6.4.4] + 304 Not Modified [RFC7232, Section 4.1] + 305 Use Proxy [RFC7231, Section 6.4.5] + 306 (Unused) [RFC7231, Section 6.4.6] + 307 Temporary Redirect [RFC7231, Section 6.4.7] + 308 Permanent Redirect [RFC7538] + 309-399 Unassigned + 400 Bad Request [RFC7231, Section 6.5.1] + 401 Unauthorized [RFC7235, Section 3.1] + 402 Payment Required [RFC7231, Section 6.5.2] + 403 Forbidden [RFC7231, Section 6.5.3] + 404 Not Found [RFC7231, Section 6.5.4] + 405 Method Not Allowed [RFC7231, Section 6.5.5] + 406 Not Acceptable [RFC7231, Section 6.5.6] + 407 Proxy Authentication Required [RFC7235, Section 3.2] + 408 Request Timeout [RFC7231, Section 6.5.7] + 409 Conflict [RFC7231, Section 6.5.8] + 410 Gone [RFC7231, Section 6.5.9] + 411 Length Required [RFC7231, Section 6.5.10] + 412 Precondition Failed [RFC7232, Section 4.2][RFC8144, Section 3.2] + 413 Payload Too Large [RFC7231, Section 6.5.11] + 414 URI Too Long [RFC7231, Section 6.5.12] + 415 Unsupported Media Type [RFC7231, Section 6.5.13][RFC7694, Section 3] + 416 Range Not Satisfiable [RFC7233, Section 4.4] + 417 Expectation Failed [RFC7231, Section 6.5.14] + 418-420 Unassigned + 421 Misdirected Request [RFC7540, Section 9.1.2] + 422 Unprocessable Entity [RFC4918] + 423 Locked [RFC4918] + 424 Failed Dependency [RFC4918] + 425 Too Early [RFC8470] + 426 Upgrade Required [RFC7231, Section 6.5.15] + 427 Unassigned + 428 Precondition Required [RFC6585] + 429 Too Many Requests [RFC6585] + 430 Unassigned + 431 Request Header Fields Too Large [RFC6585] + 432-450 Unassigned + 451 Unavailable For Legal Reasons [RFC7725] + 452-499 Unassigned + 500 Internal Server Error [RFC7231, Section 6.6.1] + 501 Not Implemented [RFC7231, Section 6.6.2] + 502 Bad Gateway [RFC7231, Section 6.6.3] + 503 Service Unavailable [RFC7231, Section 6.6.4] + 504 Gateway Timeout [RFC7231, Section 6.6.5] + 505 HTTP Version Not Supported [RFC7231, Section 6.6.6] + 506 Variant Also Negotiates [RFC2295] + 507 Insufficient Storage [RFC4918] + 508 Loop Detected [RFC5842] + 509 Unassigned + 510 Not Extended [RFC2774] + 511 Network Authentication Required [RFC6585] + 512-599 Unassigned diff --git a/.github/workflows/checkForCodeUpdates.yml b/.github/workflows/checkForCodeUpdates.yml new file mode 100644 index 0000000..1cca884 --- /dev/null +++ b/.github/workflows/checkForCodeUpdates.yml @@ -0,0 +1,19 @@ +name: Check for Code Updates + +on: + schedule: + - cron: '1 * 1 * *' + workflow_dispatch: + +jobs: + check-http-status-codes-update: + name: Check for HTTP Status Codes Update + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/github-script@v2 + with: + script: | + const path = require( 'path' ); + const scriptPath = path.resolve( './.github/checkForHttpStatusCodesUpdate.js' ); + await require( scriptPath )( { github, core } ); \ No newline at end of file From a5ff6e78af89a1d7366c11d315f841e482dee366 Mon Sep 17 00:00:00 2001 From: Jochen Ulrich Date: Thu, 9 Jul 2020 08:49:58 +0200 Subject: [PATCH 03/36] Adds package.json for development of GitHub actions --- .gitignore | 1 - package.json | 31 +++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 package.json diff --git a/.gitignore b/.gitignore index 10843f5..4d4f05c 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,5 @@ build/ _build/ build_*/ CMakeLists.txt.user -package.json package-lock.json node_modules/ \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..10999a4 --- /dev/null +++ b/package.json @@ -0,0 +1,31 @@ +{ + "name": "http-status-codes-cpp", + "version": "1.3.0", + "description": "HTTP Status Codes and Reason Phrases for C, C++ and Qt", + "directories": { + "test": "tests" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/j-ulrich/http-status-codes-cpp.git" + }, + "keywords": [ + "http", + "status-codes", + "cpp", + "qt", + "c", + "c-plus-plus", + "c++" + ], + "author": "Jochen Ulrich ", + "license": "CC0-1.0", + "bugs": { + "url": "https://github.com/j-ulrich/http-status-codes-cpp/issues" + }, + "homepage": "https://github.com/j-ulrich/http-status-codes-cpp#readme", + "devDependencies": { + "diff": "^4.0.0", + "node-fetch": "^2.3.0" + } +} From f8b66130168760c3698489e8fadc1046772ddb14 Mon Sep 17 00:00:00 2001 From: Jochen Ulrich Date: Thu, 9 Jul 2020 08:50:15 +0200 Subject: [PATCH 04/36] Enables Github action on push for development Fixes actions/setup-node reference Fixes incorrect module reference --- .github/checkForHttpStatusCodesUpdate.js | 2 +- .github/dummy.js | 13 +++++++++++++ .github/workflows/checkForCodeUpdates.yml | 6 ++++-- .gitignore | 2 +- 4 files changed, 19 insertions(+), 4 deletions(-) create mode 100644 .github/dummy.js diff --git a/.github/checkForHttpStatusCodesUpdate.js b/.github/checkForHttpStatusCodesUpdate.js index fe494fa..6bdcf03 100644 --- a/.github/checkForHttpStatusCodesUpdate.js +++ b/.github/checkForHttpStatusCodesUpdate.js @@ -1,6 +1,6 @@ const fetch = require( 'node-fetch' ); const diff = require( 'diff' ); -const fs = require( 'fs/promises' ); +const fs = require( 'fs' ).promises; const path = require( 'path' ); diff --git a/.github/dummy.js b/.github/dummy.js new file mode 100644 index 0000000..5976cba --- /dev/null +++ b/.github/dummy.js @@ -0,0 +1,13 @@ +const fetch = require( 'node-fetch' ); +const diff = require( 'diff' ); +const fs = require( 'fs' ).promises; +const path = require( 'path' ); + +module.exports = ( { github, core } ) => { + console.log( typeof fetch ); + console.log( typeof diff ); + console.log( typeof fs ); + console.log( typeof path ); + + core.info( 'works' ); +} \ No newline at end of file diff --git a/.github/workflows/checkForCodeUpdates.yml b/.github/workflows/checkForCodeUpdates.yml index 1cca884..7166d1f 100644 --- a/.github/workflows/checkForCodeUpdates.yml +++ b/.github/workflows/checkForCodeUpdates.yml @@ -1,6 +1,7 @@ name: Check for Code Updates on: + push: schedule: - cron: '1 * 1 * *' workflow_dispatch: @@ -11,9 +12,10 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 + - uses: actions/setup-node@v1 + - run: npm install - uses: actions/github-script@v2 with: script: | const path = require( 'path' ); - const scriptPath = path.resolve( './.github/checkForHttpStatusCodesUpdate.js' ); - await require( scriptPath )( { github, core } ); \ No newline at end of file + require( path.resolve( './.github/checkForHttpStatusCodesUpdate.js' ) )( { github, core } ); diff --git a/.gitignore b/.gitignore index 4d4f05c..ce73ba8 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,7 @@ !.gitignore !.appveyor.yml !.travis.yml -!.github +!.github/ build/ .build/ _build/ From 64e04a69a79198457894e982a96b775a68098916 Mon Sep 17 00:00:00 2001 From: Jochen Ulrich Date: Fri, 10 Jul 2020 01:33:57 +0200 Subject: [PATCH 05/36] Adds status log message --- .github/checkForHttpStatusCodesUpdate.js | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/checkForHttpStatusCodesUpdate.js b/.github/checkForHttpStatusCodesUpdate.js index 6bdcf03..9ae0a74 100644 --- a/.github/checkForHttpStatusCodesUpdate.js +++ b/.github/checkForHttpStatusCodesUpdate.js @@ -12,6 +12,7 @@ const checkForUpdate = async ( { github, core } ) => { const httpStatusCodes = await fetchHttpStatusCodesList(); const diffWithLastUsedVersion = await getDiffWithLastUsedVersion( httpStatusCodes.httpStatusCodesList ); if ( !diffWithLastUsedVersion ) { + core.info( 'HTTP status codes list is still up to date' ); return; } const existingGithubIssues = await searchForExistingGithubIssue( httpStatusCodes.lastUpdated, github ); From 938f9d00059b9aafacfc28a489574346290cbddd Mon Sep 17 00:00:00 2001 From: Jochen Ulrich Date: Fri, 10 Jul 2020 01:50:09 +0200 Subject: [PATCH 06/36] Testing Github action --- .github/checkForHttpStatusCodesUpdate.js | 36 +++++++++++++++-------- .github/workflows/checkForCodeUpdates.yml | 3 +- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/.github/checkForHttpStatusCodesUpdate.js b/.github/checkForHttpStatusCodesUpdate.js index 9ae0a74..0053cad 100644 --- a/.github/checkForHttpStatusCodesUpdate.js +++ b/.github/checkForHttpStatusCodesUpdate.js @@ -3,29 +3,32 @@ const diff = require( 'diff' ); const fs = require( 'fs' ).promises; const path = require( 'path' ); +let log = console; const httpStatusCodesUrl = 'https://www.iana.org/assignments/http-status-codes/http-status-codes.txt'; -const checkForUpdate = async ( { github, core } ) => { +const checkForUpdate = async ( { github, core, dryRun } ) => { try { + log = core; + const httpStatusCodes = await fetchHttpStatusCodesList(); const diffWithLastUsedVersion = await getDiffWithLastUsedVersion( httpStatusCodes.httpStatusCodesList ); if ( !diffWithLastUsedVersion ) { - core.info( 'HTTP status codes list is still up to date' ); + log.info( 'HTTP status codes list is still up to date' ); return; } const existingGithubIssues = await searchForExistingGithubIssue( httpStatusCodes.lastUpdated, github ); if ( existingGithubIssues.total_count === 0 ) { - const newIssue = await createNewGithubIssue( httpStatusCodes, diffWithLastUsedVersion, github ); - core.info( `Created issue #${newIssue.number}: ${newIssue.html_url}`); + const newIssue = await createNewGithubIssue( { httpStatusCodes, diffWithLastUsedVersion, github, dryRun } ); + log.info( `Created issue #${newIssue.number}: ${newIssue.html_url}`); } else if ( existingGithubIssues.total_count === 1 ) { - core.info( 'HTTP status codes are still up to date.' ); + log.info( 'HTTP status codes are still up to date.' ); } else { - core.warning( `Multiple issues exist for the HTTP status code update from ${httpStatusCodes.lastUpdated}` ); + log.warning( `Multiple issues exist for the HTTP status code update from ${httpStatusCodes.lastUpdated}` ); } } catch ( error ) { @@ -59,9 +62,9 @@ const searchForExistingGithubIssue = async ( lastUpdatedDate, github ) => { return searchResult; }; -const createNewGithubIssue = async ( httpStatusCodes, diffWithLastUsedVersion, github ) => { - - return github.issues.create( { +const createNewGithubIssue = async ( { httpStatusCodes, diffWithLastUsedVersion, github, dryRun } ) => { + + const newIssue = { owner: 'j-ulrich', repo: 'http-status-codes-cpp', title: `${issueTitleBase} ${httpStatusCodes.lastUpdatedDate}`, @@ -71,7 +74,14 @@ const createNewGithubIssue = async ( httpStatusCodes, diffWithLastUsedVersion, g '```diff' + '\n' + diffWithLastUsedVersion + '\n' + '```' - } ); + }; + + if ( dryRun ) { + log.info( 'Would create issue:', newIssue ); + return { total_count: 1, html_url: 'http://github.com/j-ulrich/http-status-codes-cpp/issues' }; + } + + return github.issues.create( newIssue ); }; const getDiffWithLastUsedVersion = async ( httpStatusCodeList ) => { @@ -88,14 +98,14 @@ const main = async () => { try { const httpStatusCodes = await fetchHttpStatusCodesList(); - console.log( httpStatusCodes.lastUpdated ); + log.log( httpStatusCodes.lastUpdated ); const patch = await getDiffWithLastUsedVersion( httpStatusCodes.httpStatusCodesList ); if ( patch ) { - console.log( patch ); + log.log( patch ); } } catch( reason ) { - console.error( reason ); + log.error( reason ); process.exitCode = -1; }; }; diff --git a/.github/workflows/checkForCodeUpdates.yml b/.github/workflows/checkForCodeUpdates.yml index 7166d1f..8b0b5b5 100644 --- a/.github/workflows/checkForCodeUpdates.yml +++ b/.github/workflows/checkForCodeUpdates.yml @@ -18,4 +18,5 @@ jobs: with: script: | const path = require( 'path' ); - require( path.resolve( './.github/checkForHttpStatusCodesUpdate.js' ) )( { github, core } ); + console.log( context ); + require( path.resolve( './.github/checkForHttpStatusCodesUpdate.js' ) )( { github, core, dryRun: true } ); From 921edfe757e1e33542d72cee2f4bcbd35a6e2a84 Mon Sep 17 00:00:00 2001 From: Jochen Ulrich Date: Fri, 10 Jul 2020 02:06:10 +0200 Subject: [PATCH 07/36] Uses context instead of hard coded repo information --- .github/checkForHttpStatusCodesUpdate.js | 25 ++++++++++++----------- .github/workflows/checkForCodeUpdates.yml | 2 +- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/.github/checkForHttpStatusCodesUpdate.js b/.github/checkForHttpStatusCodesUpdate.js index 0053cad..08273f4 100644 --- a/.github/checkForHttpStatusCodesUpdate.js +++ b/.github/checkForHttpStatusCodesUpdate.js @@ -7,28 +7,29 @@ let log = console; const httpStatusCodesUrl = 'https://www.iana.org/assignments/http-status-codes/http-status-codes.txt'; -const checkForUpdate = async ( { github, core, dryRun } ) => { +const checkForUpdate = async ( { github, core, context, dryRun } ) => { try { log = core; const httpStatusCodes = await fetchHttpStatusCodesList(); + const lastUpdatedDate = httpStatusCodes.lastUpdated; const diffWithLastUsedVersion = await getDiffWithLastUsedVersion( httpStatusCodes.httpStatusCodesList ); if ( !diffWithLastUsedVersion ) { log.info( 'HTTP status codes list is still up to date' ); return; } - const existingGithubIssues = await searchForExistingGithubIssue( httpStatusCodes.lastUpdated, github ); + const existingGithubIssues = await searchForExistingGithubIssue( { lastUpdatedDate, github, context } ); if ( existingGithubIssues.total_count === 0 ) { - const newIssue = await createNewGithubIssue( { httpStatusCodes, diffWithLastUsedVersion, github, dryRun } ); + const newIssue = await createNewGithubIssue( { httpStatusCodes, diffWithLastUsedVersion, github, context, dryRun } ); log.info( `Created issue #${newIssue.number}: ${newIssue.html_url}`); } else if ( existingGithubIssues.total_count === 1 ) { log.info( 'HTTP status codes are still up to date.' ); } else { - log.warning( `Multiple issues exist for the HTTP status code update from ${httpStatusCodes.lastUpdated}` ); + log.warning( `Multiple issues exist for the HTTP status code update from ${lastUpdatedDate}` ); } } catch ( error ) { @@ -54,19 +55,19 @@ const fetchHttpStatusCodesList = async () => { const issueTitleBase = 'IANA HTTP Status Code Update'; -const searchForExistingGithubIssue = async ( lastUpdatedDate, github ) => { - const query = [ issueTitleBase, lastUpdatedDate, 'in:title', 'repo:j-ulrich/http-status-codes-cpp', 'type:issue' ].join( '+' ); +const searchForExistingGithubIssue = async ( { lastUpdatedDate, github, context } ) => { + const query = [ issueTitleBase, lastUpdatedDate, 'in:title', `repo:${context.repository.full_name}`, 'type:issue' ].join( '+' ); const searchResult = await github.search.issuesAndPullRequests( { q: query, } ); return searchResult; }; -const createNewGithubIssue = async ( { httpStatusCodes, diffWithLastUsedVersion, github, dryRun } ) => { +const createNewGithubIssue = async ( { httpStatusCodes, diffWithLastUsedVersion, github, context, dryRun } ) => { const newIssue = { - owner: 'j-ulrich', - repo: 'http-status-codes-cpp', + owner: context.repo.owner, + repo: context.repo.repo, title: `${issueTitleBase} ${httpStatusCodes.lastUpdatedDate}`, body: `The HTTP status codes list has been updated on ${httpStatusCodes.lastUpdatedDate}.` + '\n' + 'See https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml' + '\n\n' + @@ -77,10 +78,10 @@ const createNewGithubIssue = async ( { httpStatusCodes, diffWithLastUsedVersion, }; if ( dryRun ) { - log.info( 'Would create issue:', newIssue ); - return { total_count: 1, html_url: 'http://github.com/j-ulrich/http-status-codes-cpp/issues' }; + log.info( 'Would create issue:\n', JSON.stringify( newIssue ) ); + return { total_count: 1, html_url: context.repo.issues_url }; } - + return github.issues.create( newIssue ); }; diff --git a/.github/workflows/checkForCodeUpdates.yml b/.github/workflows/checkForCodeUpdates.yml index 8b0b5b5..172c22a 100644 --- a/.github/workflows/checkForCodeUpdates.yml +++ b/.github/workflows/checkForCodeUpdates.yml @@ -19,4 +19,4 @@ jobs: script: | const path = require( 'path' ); console.log( context ); - require( path.resolve( './.github/checkForHttpStatusCodesUpdate.js' ) )( { github, core, dryRun: true } ); + require( path.resolve( './.github/checkForHttpStatusCodesUpdate.js' ) )( { github, core, context, dryRun: true } ); From c22d4d71211de3f88544259a8b99c154084b7359 Mon Sep 17 00:00:00 2001 From: Jochen Ulrich Date: Fri, 10 Jul 2020 02:07:46 +0200 Subject: [PATCH 08/36] Tests script --- .github/checkForHttpStatusCodesUpdate.js | 4 ++++ .github/workflows/checkForCodeUpdates.yml | 3 +-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/checkForHttpStatusCodesUpdate.js b/.github/checkForHttpStatusCodesUpdate.js index 08273f4..75384de 100644 --- a/.github/checkForHttpStatusCodesUpdate.js +++ b/.github/checkForHttpStatusCodesUpdate.js @@ -15,10 +15,12 @@ const checkForUpdate = async ( { github, core, context, dryRun } ) => { const httpStatusCodes = await fetchHttpStatusCodesList(); const lastUpdatedDate = httpStatusCodes.lastUpdated; const diffWithLastUsedVersion = await getDiffWithLastUsedVersion( httpStatusCodes.httpStatusCodesList ); + /* if ( !diffWithLastUsedVersion ) { log.info( 'HTTP status codes list is still up to date' ); return; } + */ const existingGithubIssues = await searchForExistingGithubIssue( { lastUpdatedDate, github, context } ); if ( existingGithubIssues.total_count === 0 ) { @@ -88,9 +90,11 @@ const createNewGithubIssue = async ( { httpStatusCodes, diffWithLastUsedVersion, const getDiffWithLastUsedVersion = async ( httpStatusCodeList ) => { const pathToLastUsedVersion = path.resolve( './.github/http-status-codes.txt' ); const lastUsedVersion = await fs.readFile( pathToLastUsedVersion, { encoding: 'utf-8' } ); + /* if ( lastUsedVersion === httpStatusCodeList ) { return null; } + */ const patch = diff.createPatch( 'http-status-codes.txt', lastUsedVersion, httpStatusCodeList ); return patch; }; diff --git a/.github/workflows/checkForCodeUpdates.yml b/.github/workflows/checkForCodeUpdates.yml index 172c22a..4f8a504 100644 --- a/.github/workflows/checkForCodeUpdates.yml +++ b/.github/workflows/checkForCodeUpdates.yml @@ -18,5 +18,4 @@ jobs: with: script: | const path = require( 'path' ); - console.log( context ); - require( path.resolve( './.github/checkForHttpStatusCodesUpdate.js' ) )( { github, core, context, dryRun: true } ); + await require( path.resolve( './.github/checkForHttpStatusCodesUpdate.js' ) )( { github, core, context, dryRun: true } ); From 0cd4e7d2b40a893a5c45f753c4791d24c8069629 Mon Sep 17 00:00:00 2001 From: Jochen Ulrich Date: Fri, 10 Jul 2020 02:08:41 +0200 Subject: [PATCH 09/36] Fixes context access --- .github/checkForHttpStatusCodesUpdate.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/checkForHttpStatusCodesUpdate.js b/.github/checkForHttpStatusCodesUpdate.js index 75384de..e96e1be 100644 --- a/.github/checkForHttpStatusCodesUpdate.js +++ b/.github/checkForHttpStatusCodesUpdate.js @@ -58,7 +58,7 @@ const fetchHttpStatusCodesList = async () => { const issueTitleBase = 'IANA HTTP Status Code Update'; const searchForExistingGithubIssue = async ( { lastUpdatedDate, github, context } ) => { - const query = [ issueTitleBase, lastUpdatedDate, 'in:title', `repo:${context.repository.full_name}`, 'type:issue' ].join( '+' ); + const query = [ issueTitleBase, lastUpdatedDate, 'in:title', `repo:${context.repo.full_name}`, 'type:issue' ].join( '+' ); const searchResult = await github.search.issuesAndPullRequests( { q: query, } ); From f637d37d9bcecdd783d3eda42fdc78a284791456 Mon Sep 17 00:00:00 2001 From: Jochen Ulrich Date: Fri, 10 Jul 2020 02:10:52 +0200 Subject: [PATCH 10/36] Fixes context access --- .github/checkForHttpStatusCodesUpdate.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/checkForHttpStatusCodesUpdate.js b/.github/checkForHttpStatusCodesUpdate.js index e96e1be..0731b81 100644 --- a/.github/checkForHttpStatusCodesUpdate.js +++ b/.github/checkForHttpStatusCodesUpdate.js @@ -58,7 +58,7 @@ const fetchHttpStatusCodesList = async () => { const issueTitleBase = 'IANA HTTP Status Code Update'; const searchForExistingGithubIssue = async ( { lastUpdatedDate, github, context } ) => { - const query = [ issueTitleBase, lastUpdatedDate, 'in:title', `repo:${context.repo.full_name}`, 'type:issue' ].join( '+' ); + const query = [ issueTitleBase, lastUpdatedDate, 'in:title', `repo:${context.payload.repository.full_name}`, 'type:issue' ].join( '+' ); const searchResult = await github.search.issuesAndPullRequests( { q: query, } ); From 7c00ec40077328d7fe5998a4f2f85ba82b8f36e8 Mon Sep 17 00:00:00 2001 From: Jochen Ulrich Date: Fri, 10 Jul 2020 02:14:56 +0200 Subject: [PATCH 11/36] Debugging issue search --- .github/checkForHttpStatusCodesUpdate.js | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/checkForHttpStatusCodesUpdate.js b/.github/checkForHttpStatusCodesUpdate.js index 0731b81..772b5be 100644 --- a/.github/checkForHttpStatusCodesUpdate.js +++ b/.github/checkForHttpStatusCodesUpdate.js @@ -32,6 +32,7 @@ const checkForUpdate = async ( { github, core, context, dryRun } ) => { } else { log.warning( `Multiple issues exist for the HTTP status code update from ${lastUpdatedDate}` ); + log.debug( existingGithubIssues ); } } catch ( error ) { From cae840d6f019ef4dffcfc5ce708fb6e23f03c706 Mon Sep 17 00:00:00 2001 From: Jochen Ulrich Date: Fri, 10 Jul 2020 02:17:15 +0200 Subject: [PATCH 12/36] Fixes issue search result handling --- .github/checkForHttpStatusCodesUpdate.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/checkForHttpStatusCodesUpdate.js b/.github/checkForHttpStatusCodesUpdate.js index 772b5be..2217330 100644 --- a/.github/checkForHttpStatusCodesUpdate.js +++ b/.github/checkForHttpStatusCodesUpdate.js @@ -63,7 +63,7 @@ const searchForExistingGithubIssue = async ( { lastUpdatedDate, github, context const searchResult = await github.search.issuesAndPullRequests( { q: query, } ); - return searchResult; + return searchResult.data; }; const createNewGithubIssue = async ( { httpStatusCodes, diffWithLastUsedVersion, github, context, dryRun } ) => { From e70752d70916fe8dc592d9c665239e1a9e0d496a Mon Sep 17 00:00:00 2001 From: Jochen Ulrich Date: Fri, 10 Jul 2020 02:19:42 +0200 Subject: [PATCH 13/36] Fixes output printing --- .github/checkForHttpStatusCodesUpdate.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/checkForHttpStatusCodesUpdate.js b/.github/checkForHttpStatusCodesUpdate.js index 2217330..21429fa 100644 --- a/.github/checkForHttpStatusCodesUpdate.js +++ b/.github/checkForHttpStatusCodesUpdate.js @@ -31,8 +31,7 @@ const checkForUpdate = async ( { github, core, context, dryRun } ) => { log.info( 'HTTP status codes are still up to date.' ); } else { - log.warning( `Multiple issues exist for the HTTP status code update from ${lastUpdatedDate}` ); - log.debug( existingGithubIssues ); + log.warning( `Multiple issues exist for the HTTP status code update from ${lastUpdatedDate}:\n${ JSON.stringify( existingGithubIssues ) }` ); } } catch ( error ) { @@ -72,7 +71,7 @@ const createNewGithubIssue = async ( { httpStatusCodes, diffWithLastUsedVersion, owner: context.repo.owner, repo: context.repo.repo, title: `${issueTitleBase} ${httpStatusCodes.lastUpdatedDate}`, - body: `The HTTP status codes list has been updated on ${httpStatusCodes.lastUpdatedDate}.` + '\n' + + body: `The HTTP status codes list has been updated on ${httpStatusCodes.lastUpdatedDate}. ` + '\n' + 'See https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml' + '\n\n' + '## Diff ##' + '\n' + '```diff' + '\n' + @@ -81,7 +80,7 @@ const createNewGithubIssue = async ( { httpStatusCodes, diffWithLastUsedVersion, }; if ( dryRun ) { - log.info( 'Would create issue:\n', JSON.stringify( newIssue ) ); + log.info( `Would create issue:\n${ JSON.stringify( newIssue ) }` ); return { total_count: 1, html_url: context.repo.issues_url }; } From 4a012ff654d8ef0e63c0eb092d4873f4bf715893 Mon Sep 17 00:00:00 2001 From: Jochen Ulrich Date: Fri, 10 Jul 2020 02:21:00 +0200 Subject: [PATCH 14/36] Improves output printing --- .github/checkForHttpStatusCodesUpdate.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/checkForHttpStatusCodesUpdate.js b/.github/checkForHttpStatusCodesUpdate.js index 21429fa..b20b65b 100644 --- a/.github/checkForHttpStatusCodesUpdate.js +++ b/.github/checkForHttpStatusCodesUpdate.js @@ -31,7 +31,7 @@ const checkForUpdate = async ( { github, core, context, dryRun } ) => { log.info( 'HTTP status codes are still up to date.' ); } else { - log.warning( `Multiple issues exist for the HTTP status code update from ${lastUpdatedDate}:\n${ JSON.stringify( existingGithubIssues ) }` ); + log.warning( `Multiple issues exist for the HTTP status code update from ${lastUpdatedDate}:\n${ JSON.stringify( existingGithubIssues, undefined, 4 ) }` ); } } catch ( error ) { @@ -80,7 +80,7 @@ const createNewGithubIssue = async ( { httpStatusCodes, diffWithLastUsedVersion, }; if ( dryRun ) { - log.info( `Would create issue:\n${ JSON.stringify( newIssue ) }` ); + log.info( `Would create issue:\n${ JSON.stringify( newIssue, null, 4 ) }` ); return { total_count: 1, html_url: context.repo.issues_url }; } From aada465ad38cda4657bda62f7545f2f40d5b3bbc Mon Sep 17 00:00:00 2001 From: Jochen Ulrich Date: Fri, 10 Jul 2020 02:22:34 +0200 Subject: [PATCH 15/36] Fixes output printing --- .github/checkForHttpStatusCodesUpdate.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/checkForHttpStatusCodesUpdate.js b/.github/checkForHttpStatusCodesUpdate.js index b20b65b..bc72d51 100644 --- a/.github/checkForHttpStatusCodesUpdate.js +++ b/.github/checkForHttpStatusCodesUpdate.js @@ -81,7 +81,7 @@ const createNewGithubIssue = async ( { httpStatusCodes, diffWithLastUsedVersion, if ( dryRun ) { log.info( `Would create issue:\n${ JSON.stringify( newIssue, null, 4 ) }` ); - return { total_count: 1, html_url: context.repo.issues_url }; + return { number: 0, html_url: context.payload.repository.issues_url }; } return github.issues.create( newIssue ); From 20c8331e6dc6d283ba48f624e85c561ae2fa9307 Mon Sep 17 00:00:00 2001 From: Jochen Ulrich Date: Fri, 10 Jul 2020 02:25:33 +0200 Subject: [PATCH 16/36] Fixes missing date in issue body --- .github/checkForHttpStatusCodesUpdate.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/checkForHttpStatusCodesUpdate.js b/.github/checkForHttpStatusCodesUpdate.js index bc72d51..a3bee28 100644 --- a/.github/checkForHttpStatusCodesUpdate.js +++ b/.github/checkForHttpStatusCodesUpdate.js @@ -71,7 +71,7 @@ const createNewGithubIssue = async ( { httpStatusCodes, diffWithLastUsedVersion, owner: context.repo.owner, repo: context.repo.repo, title: `${issueTitleBase} ${httpStatusCodes.lastUpdatedDate}`, - body: `The HTTP status codes list has been updated on ${httpStatusCodes.lastUpdatedDate}. ` + '\n' + + body: `The HTTP status codes list has been updated on ${httpStatusCodes.lastUpdated}. ` + '\n' + 'See https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml' + '\n\n' + '## Diff ##' + '\n' + '```diff' + '\n' + From 34091c5bea75dac1600a9431020fd3ba4628b75e Mon Sep 17 00:00:00 2001 From: Jochen Ulrich Date: Fri, 10 Jul 2020 02:27:06 +0200 Subject: [PATCH 17/36] Disables dryRun --- .github/workflows/checkForCodeUpdates.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/checkForCodeUpdates.yml b/.github/workflows/checkForCodeUpdates.yml index 4f8a504..9a15de3 100644 --- a/.github/workflows/checkForCodeUpdates.yml +++ b/.github/workflows/checkForCodeUpdates.yml @@ -18,4 +18,4 @@ jobs: with: script: | const path = require( 'path' ); - await require( path.resolve( './.github/checkForHttpStatusCodesUpdate.js' ) )( { github, core, context, dryRun: true } ); + await require( path.resolve( './.github/checkForHttpStatusCodesUpdate.js' ) )( { github, core, context, dryRun: false } ); From 2b8c69acd1ae482fa7444e0fdaa898ab6cb14225 Mon Sep 17 00:00:00 2001 From: Jochen Ulrich Date: Fri, 10 Jul 2020 02:30:11 +0200 Subject: [PATCH 18/36] Fixes undefined fields --- .github/checkForHttpStatusCodesUpdate.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/checkForHttpStatusCodesUpdate.js b/.github/checkForHttpStatusCodesUpdate.js index a3bee28..f443f78 100644 --- a/.github/checkForHttpStatusCodesUpdate.js +++ b/.github/checkForHttpStatusCodesUpdate.js @@ -59,10 +59,10 @@ const issueTitleBase = 'IANA HTTP Status Code Update'; const searchForExistingGithubIssue = async ( { lastUpdatedDate, github, context } ) => { const query = [ issueTitleBase, lastUpdatedDate, 'in:title', `repo:${context.payload.repository.full_name}`, 'type:issue' ].join( '+' ); - const searchResult = await github.search.issuesAndPullRequests( { + const searchResponse = await github.search.issuesAndPullRequests( { q: query, } ); - return searchResult.data; + return searchResponse.data; }; const createNewGithubIssue = async ( { httpStatusCodes, diffWithLastUsedVersion, github, context, dryRun } ) => { @@ -70,7 +70,7 @@ const createNewGithubIssue = async ( { httpStatusCodes, diffWithLastUsedVersion, const newIssue = { owner: context.repo.owner, repo: context.repo.repo, - title: `${issueTitleBase} ${httpStatusCodes.lastUpdatedDate}`, + title: `${issueTitleBase} ${httpStatusCodes.lastUpdated}`, body: `The HTTP status codes list has been updated on ${httpStatusCodes.lastUpdated}. ` + '\n' + 'See https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml' + '\n\n' + '## Diff ##' + '\n' + @@ -84,7 +84,8 @@ const createNewGithubIssue = async ( { httpStatusCodes, diffWithLastUsedVersion, return { number: 0, html_url: context.payload.repository.issues_url }; } - return github.issues.create( newIssue ); + const issueResponse = await github.issues.create( newIssue ); + return issueResponse.data; }; const getDiffWithLastUsedVersion = async ( httpStatusCodeList ) => { From 1718ace2679a6632cf825493054a8d42a752fc10 Mon Sep 17 00:00:00 2001 From: Jochen Ulrich Date: Fri, 10 Jul 2020 02:36:41 +0200 Subject: [PATCH 19/36] Improves logging --- .github/checkForHttpStatusCodesUpdate.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/checkForHttpStatusCodesUpdate.js b/.github/checkForHttpStatusCodesUpdate.js index f443f78..50592aa 100644 --- a/.github/checkForHttpStatusCodesUpdate.js +++ b/.github/checkForHttpStatusCodesUpdate.js @@ -21,6 +21,8 @@ const checkForUpdate = async ( { github, core, context, dryRun } ) => { return; } */ + log.warning( 'HTTP status codes list is outdated!' ); + const existingGithubIssues = await searchForExistingGithubIssue( { lastUpdatedDate, github, context } ); if ( existingGithubIssues.total_count === 0 ) { @@ -28,7 +30,7 @@ const checkForUpdate = async ( { github, core, context, dryRun } ) => { log.info( `Created issue #${newIssue.number}: ${newIssue.html_url}`); } else if ( existingGithubIssues.total_count === 1 ) { - log.info( 'HTTP status codes are still up to date.' ); + log.info( 'An issue already exists for this update.' ); } else { log.warning( `Multiple issues exist for the HTTP status code update from ${lastUpdatedDate}:\n${ JSON.stringify( existingGithubIssues, undefined, 4 ) }` ); From b1bec00488c03d4be7b00f166d408e7a101006d0 Mon Sep 17 00:00:00 2001 From: Jochen Ulrich Date: Fri, 10 Jul 2020 02:41:58 +0200 Subject: [PATCH 20/36] Re-enables checks after testing --- .github/checkForHttpStatusCodesUpdate.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/checkForHttpStatusCodesUpdate.js b/.github/checkForHttpStatusCodesUpdate.js index 50592aa..3ad8690 100644 --- a/.github/checkForHttpStatusCodesUpdate.js +++ b/.github/checkForHttpStatusCodesUpdate.js @@ -15,12 +15,10 @@ const checkForUpdate = async ( { github, core, context, dryRun } ) => { const httpStatusCodes = await fetchHttpStatusCodesList(); const lastUpdatedDate = httpStatusCodes.lastUpdated; const diffWithLastUsedVersion = await getDiffWithLastUsedVersion( httpStatusCodes.httpStatusCodesList ); - /* if ( !diffWithLastUsedVersion ) { log.info( 'HTTP status codes list is still up to date' ); return; } - */ log.warning( 'HTTP status codes list is outdated!' ); const existingGithubIssues = await searchForExistingGithubIssue( { lastUpdatedDate, github, context } ); @@ -93,11 +91,9 @@ const createNewGithubIssue = async ( { httpStatusCodes, diffWithLastUsedVersion, const getDiffWithLastUsedVersion = async ( httpStatusCodeList ) => { const pathToLastUsedVersion = path.resolve( './.github/http-status-codes.txt' ); const lastUsedVersion = await fs.readFile( pathToLastUsedVersion, { encoding: 'utf-8' } ); - /* if ( lastUsedVersion === httpStatusCodeList ) { return null; } - */ const patch = diff.createPatch( 'http-status-codes.txt', lastUsedVersion, httpStatusCodeList ); return patch; }; From 9a335c9c8bd361b330c36a8eaf6b9986c8e2dac9 Mon Sep 17 00:00:00 2001 From: Jochen Ulrich Date: Fri, 10 Jul 2020 10:31:24 +0200 Subject: [PATCH 21/36] Refactors check script --- .github/checkForHttpStatusCodesUpdate.js | 58 +++++++++--------------- .github/dummy.js | 13 ------ .github/githubIssues.js | 23 ++++++++++ 3 files changed, 45 insertions(+), 49 deletions(-) delete mode 100644 .github/dummy.js create mode 100644 .github/githubIssues.js diff --git a/.github/checkForHttpStatusCodesUpdate.js b/.github/checkForHttpStatusCodesUpdate.js index 3ad8690..2ae5532 100644 --- a/.github/checkForHttpStatusCodesUpdate.js +++ b/.github/checkForHttpStatusCodesUpdate.js @@ -2,10 +2,12 @@ const fetch = require( 'node-fetch' ); const diff = require( 'diff' ); const fs = require( 'fs' ).promises; const path = require( 'path' ); +const githubIssues = require( './githubIssues.js' ); let log = console; const httpStatusCodesUrl = 'https://www.iana.org/assignments/http-status-codes/http-status-codes.txt'; +const issueTitleBase = 'IANA HTTP Status Code Update'; const checkForUpdate = async ( { github, core, context, dryRun } ) => { try @@ -21,11 +23,10 @@ const checkForUpdate = async ( { github, core, context, dryRun } ) => { } log.warning( 'HTTP status codes list is outdated!' ); - const existingGithubIssues = await searchForExistingGithubIssue( { lastUpdatedDate, github, context } ); + const existingGithubIssues = await githubIssues.searchForExistingGithubIssue( { keywords: [ issueTitleBase, lastUpdatedDate ], github, context } ); if ( existingGithubIssues.total_count === 0 ) { - const newIssue = await createNewGithubIssue( { httpStatusCodes, diffWithLastUsedVersion, github, context, dryRun } ); - log.info( `Created issue #${newIssue.number}: ${newIssue.html_url}`); + createNewGithubIssue( { lastUpdatedDate, diffWithLastUsedVersion, github, context, dryRun } ); } else if ( existingGithubIssues.total_count === 1 ) { log.info( 'An issue already exists for this update.' ); @@ -55,39 +56,6 @@ const fetchHttpStatusCodesList = async () => { return { lastUpdated, httpStatusCodesList }; }; -const issueTitleBase = 'IANA HTTP Status Code Update'; - -const searchForExistingGithubIssue = async ( { lastUpdatedDate, github, context } ) => { - const query = [ issueTitleBase, lastUpdatedDate, 'in:title', `repo:${context.payload.repository.full_name}`, 'type:issue' ].join( '+' ); - const searchResponse = await github.search.issuesAndPullRequests( { - q: query, - } ); - return searchResponse.data; -}; - -const createNewGithubIssue = async ( { httpStatusCodes, diffWithLastUsedVersion, github, context, dryRun } ) => { - - const newIssue = { - owner: context.repo.owner, - repo: context.repo.repo, - title: `${issueTitleBase} ${httpStatusCodes.lastUpdated}`, - body: `The HTTP status codes list has been updated on ${httpStatusCodes.lastUpdated}. ` + '\n' + - 'See https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml' + '\n\n' + - '## Diff ##' + '\n' + - '```diff' + '\n' + - diffWithLastUsedVersion + '\n' + - '```' - }; - - if ( dryRun ) { - log.info( `Would create issue:\n${ JSON.stringify( newIssue, null, 4 ) }` ); - return { number: 0, html_url: context.payload.repository.issues_url }; - } - - const issueResponse = await github.issues.create( newIssue ); - return issueResponse.data; -}; - const getDiffWithLastUsedVersion = async ( httpStatusCodeList ) => { const pathToLastUsedVersion = path.resolve( './.github/http-status-codes.txt' ); const lastUsedVersion = await fs.readFile( pathToLastUsedVersion, { encoding: 'utf-8' } ); @@ -98,6 +66,24 @@ const getDiffWithLastUsedVersion = async ( httpStatusCodeList ) => { return patch; }; +const createNewGithubIssue = async ( { lastUpdatedDate, diffWithLastUsedVersion, github, context, dryRun } ) => { + const title = `${issueTitleBase} ${lastUpdatedDate}`; + const body = `The HTTP status codes list has been updated on ${lastUpdatedDate}. ` + '\n' + + 'See https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml' + '\n\n' + + '## Diff ##' + '\n' + + '```diff' + '\n' + + diffWithLastUsedVersion + '\n' + + '```'; + + if ( dryRun ) { + log.info( `Would create issue:\n${ JSON.stringify( { title, body }, null, 4 ) }` ); + } + else { + const newIssue = await githubIssues.createNewGithubIssue( { title, body, github, context } ); + log.info( `Created issue #${newIssue.number}: ${newIssue.html_url}`); + } +}; + const main = async () => { try { diff --git a/.github/dummy.js b/.github/dummy.js deleted file mode 100644 index 5976cba..0000000 --- a/.github/dummy.js +++ /dev/null @@ -1,13 +0,0 @@ -const fetch = require( 'node-fetch' ); -const diff = require( 'diff' ); -const fs = require( 'fs' ).promises; -const path = require( 'path' ); - -module.exports = ( { github, core } ) => { - console.log( typeof fetch ); - console.log( typeof diff ); - console.log( typeof fs ); - console.log( typeof path ); - - core.info( 'works' ); -} \ No newline at end of file diff --git a/.github/githubIssues.js b/.github/githubIssues.js new file mode 100644 index 0000000..43f36e4 --- /dev/null +++ b/.github/githubIssues.js @@ -0,0 +1,23 @@ + +const searchForExistingGithubIssue = async ( { keywords, github, context } ) => { + const query = keywords.concat( [ 'in:title', `repo:${context.payload.repository.full_name}`, 'type:issue' ] ).join( '+' ); + const searchResponse = await github.search.issuesAndPullRequests( { + q: query, + } ); + return searchResponse.data; +}; + +const createNewGithubIssue = async ( { title, body, github, context } ) => { + + const newIssue = { + owner: context.repo.owner, + repo: context.repo.repo, + title, + body + }; + + const issueResponse = await github.issues.create( newIssue ); + return issueResponse.data; +}; + +module.exports = { searchForExistingGithubIssue, createNewGithubIssue }; \ No newline at end of file From 67faab8d2b05038cb9f5fcf703b3d9e522083fcf Mon Sep 17 00:00:00 2001 From: Jochen Ulrich Date: Fri, 10 Jul 2020 17:55:59 +0200 Subject: [PATCH 22/36] WIP: Adds script to check for QNetworkReply error code uodate --- .github/checkQNetworkReplyErrorCodeUpdate.js | 119 +++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100644 .github/checkQNetworkReplyErrorCodeUpdate.js diff --git a/.github/checkQNetworkReplyErrorCodeUpdate.js b/.github/checkQNetworkReplyErrorCodeUpdate.js new file mode 100644 index 0000000..e83b404 --- /dev/null +++ b/.github/checkQNetworkReplyErrorCodeUpdate.js @@ -0,0 +1,119 @@ +const diff = require( 'diff' ); +const fs = require( 'fs' ).promises; +const path = require( 'path' ); +const githubIssues = require( './githubIssues.js' ); + +let log = console; + +const qnetworkReplyHeaderUrl = 'https://code.qt.io/cgit/qt/qtbase.git/plain/src/network/access/qnetworkreply.h'; +const issueTitleBase = 'QNetworkReply Error Code Update'; + +const checkForUpdate = async ( { github, core, context, dryRun } ) => { + try + { + log = core; + + const qnetworkReplyErrorCodes = await fetchQNetworkReplyErrorCodeList( github ); + const lastUpdatedDate = httpStatusCodes.lastUpdated; + const diffWithLastUsedVersion = await getDiffWithLastUsedVersion( httpStatusCodes.httpStatusCodesList ); + if ( !diffWithLastUsedVersion ) { + log.info( 'HTTP status codes list is still up to date' ); + return; + } + log.warning( 'HTTP status codes list is outdated!' ); + + const existingGithubIssues = await githubIssues.searchForExistingGithubIssue( { keywords: [ issueTitleBase, lastUpdatedDate ], github, context } ); + + if ( existingGithubIssues.total_count === 0 ) { + createNewGithubIssue( { lastUpdatedDate, diffWithLastUsedVersion, github, context, dryRun } ); + } + else if ( existingGithubIssues.total_count === 1 ) { + log.info( 'An issue already exists for this update.' ); + } + else { + log.warning( `Multiple issues exist for the HTTP status code update from ${lastUpdatedDate}:\n${ JSON.stringify( existingGithubIssues, undefined, 4 ) }` ); + } + } + catch ( error ) { + core.setFailed( `Could not check for HTTP status codes updates: ${error}` ); + throw error; + } +}; + +const fetchQNetworkReplyErrorCodeList = async ( github ) => { + + const response = await github.repos.getContent( { + owner: 'qt', + repo: 'qtbase', + path: 'src/network/access/qnetworkreply.h', + ref: 'dev' + } ); + const commitId = response.sha; + + const qnetworkReplyHeaderSource = decodeRepoContent( response ); + const qnetworkReplyErrorCodes = extractQNetworkReplyErrorCodes( qnetworkReplyHeaderSource ); + + return { commitId, qnetworkReplyErrorCodes }; +}; + +const decodeRepoContent = ( response ) => { + try { + return Buffer.from( response.content, response.encoding ).toString( 'utf-8' ); + } + catch( e ) { + throw Error( `Unsupported repository content encoding: ${response.encoding}\nOriginal exception: ${e}` ); + } +}; + +const extractQNetworkReplyErrorCodes = ( qnetworkReplyHeaderSource ) => { + +} + +const getDiffWithLastUsedVersion = async ( httpStatusCodeList ) => { + const pathToLastUsedVersion = path.resolve( './.github/http-status-codes.txt' ); + const lastUsedVersion = await fs.readFile( pathToLastUsedVersion, { encoding: 'utf-8' } ); + if ( lastUsedVersion === httpStatusCodeList ) { + return null; + } + const patch = diff.createPatch( 'http-status-codes.txt', lastUsedVersion, httpStatusCodeList ); + return patch; +}; + +const createNewGithubIssue = async ( { diffWithLastUsedVersion, github, context, dryRun } ) => { + const title = `${issueTitleBase} ${lastUpdatedDate}`; + const body = 'The `QNetworkReply::NetworkError` codes list has been updated. \n' + + 'See https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml' + '\n\n' + + '## Diff ##' + '\n' + + '```diff' + '\n' + + diffWithLastUsedVersion + '\n' + + '```'; + + if ( dryRun ) { + log.info( `Would create issue:\n${ JSON.stringify( { title, body }, null, 4 ) }` ); + } + else { + const newIssue = await githubIssues.createNewGithubIssue( { title, body, github, context } ); + log.info( `Created issue #${newIssue.number}: ${newIssue.html_url}`); + } +}; + +const main = async () => { + try + { + const qnetworkReplyErrorCodes = await fetchQNetworkReplyErrorCodeList(); + const patch = await getDiffWithLastUsedVersion( qnetworkReplyErrorCodes ); + if ( patch ) { + log.log( patch ); + } + } + catch( reason ) { + log.error( reason ); + process.exitCode = -1; + }; +}; + +module.exports = checkForUpdate; + +if ( require.main === module ) { + main(); +} \ No newline at end of file From d7fe973fa66734ccab07157dc9d90501938e33b0 Mon Sep 17 00:00:00 2001 From: Jochen Ulrich Date: Thu, 16 Jul 2020 00:37:19 +0200 Subject: [PATCH 23/36] Implements checking for QNetworkReply error codes updates --- .github/QNetworkReplyErroCodes.txt | 34 ++++++++++ .github/checkQNetworkReplyErrorCodeUpdate.js | 67 +++++++++++++------- 2 files changed, 79 insertions(+), 22 deletions(-) create mode 100644 .github/QNetworkReplyErroCodes.txt diff --git a/.github/QNetworkReplyErroCodes.txt b/.github/QNetworkReplyErroCodes.txt new file mode 100644 index 0000000..47881e3 --- /dev/null +++ b/.github/QNetworkReplyErroCodes.txt @@ -0,0 +1,34 @@ +NoError=0 +ConnectionRefusedError=1 +RemoteHostClosedError +HostNotFoundError +TimeoutError +OperationCanceledError +SslHandshakeFailedError +TemporaryNetworkFailureError +NetworkSessionFailedError +BackgroundRequestNotAllowedError +TooManyRedirectsError +InsecureRedirectError +UnknownNetworkError=99 +ProxyConnectionRefusedError=101 +ProxyConnectionClosedError +ProxyNotFoundError +ProxyTimeoutError +ProxyAuthenticationRequiredError +UnknownProxyError=199 +ContentAccessDenied=201 +ContentOperationNotPermittedError +ContentNotFoundError +AuthenticationRequiredError +ContentReSendError +ContentConflictError +ContentGoneError +UnknownContentError=299 +ProtocolUnknownError=301 +ProtocolInvalidOperationError +ProtocolFailure=399 +InternalServerError=401 +OperationNotImplementedError +ServiceUnavailableError +UnknownServerError=499 \ No newline at end of file diff --git a/.github/checkQNetworkReplyErrorCodeUpdate.js b/.github/checkQNetworkReplyErrorCodeUpdate.js index e83b404..8fa1adb 100644 --- a/.github/checkQNetworkReplyErrorCodeUpdate.js +++ b/.github/checkQNetworkReplyErrorCodeUpdate.js @@ -1,3 +1,4 @@ +const fetch = require( 'node-fetch' ); const diff = require( 'diff' ); const fs = require( 'fs' ).promises; const path = require( 'path' ); @@ -5,7 +6,7 @@ const githubIssues = require( './githubIssues.js' ); let log = console; -const qnetworkReplyHeaderUrl = 'https://code.qt.io/cgit/qt/qtbase.git/plain/src/network/access/qnetworkreply.h'; +const qNetworkReplyHeaderUrl = 'https://code.qt.io/cgit/qt/qtbase.git/plain/src/network/access/qnetworkreply.h'; const issueTitleBase = 'QNetworkReply Error Code Update'; const checkForUpdate = async ( { github, core, context, dryRun } ) => { @@ -13,25 +14,24 @@ const checkForUpdate = async ( { github, core, context, dryRun } ) => { { log = core; - const qnetworkReplyErrorCodes = await fetchQNetworkReplyErrorCodeList( github ); - const lastUpdatedDate = httpStatusCodes.lastUpdated; - const diffWithLastUsedVersion = await getDiffWithLastUsedVersion( httpStatusCodes.httpStatusCodesList ); + const { commitId, qNetworkReplyErrorCodes } = await fetchQNetworkReplyErrorCodeListFromGitHub( github ); + const diffWithLastUsedVersion = await getDiffWithLastUsedVersion( qNetworkReplyErrorCodes ); if ( !diffWithLastUsedVersion ) { - log.info( 'HTTP status codes list is still up to date' ); + log.info( 'QNetworkReply error codes list is still up to date' ); return; } - log.warning( 'HTTP status codes list is outdated!' ); + log.warning( 'QNetworkReply error codes list is outdated!' ); - const existingGithubIssues = await githubIssues.searchForExistingGithubIssue( { keywords: [ issueTitleBase, lastUpdatedDate ], github, context } ); + const existingGithubIssues = await githubIssues.searchForExistingGithubIssue( { keywords: [ issueTitleBase, shortenCommitId( commitId ) ], github, context } ); if ( existingGithubIssues.total_count === 0 ) { - createNewGithubIssue( { lastUpdatedDate, diffWithLastUsedVersion, github, context, dryRun } ); + createNewGithubIssue( { commitId, diffWithLastUsedVersion, github, context, dryRun } ); } else if ( existingGithubIssues.total_count === 1 ) { log.info( 'An issue already exists for this update.' ); } else { - log.warning( `Multiple issues exist for the HTTP status code update from ${lastUpdatedDate}:\n${ JSON.stringify( existingGithubIssues, undefined, 4 ) }` ); + log.warning( `Multiple issues exist for the QNetworkReply error codes update with id ${commitId}:\n${ JSON.stringify( existingGithubIssues, undefined, 4 ) }` ); } } catch ( error ) { @@ -40,7 +40,11 @@ const checkForUpdate = async ( { github, core, context, dryRun } ) => { } }; -const fetchQNetworkReplyErrorCodeList = async ( github ) => { +const shortenCommitId = commitId => { + return commitId.substring( 0, 6 ) +}; + +const fetchQNetworkReplyErrorCodeListFromGitHub = async ( github ) => { const response = await github.repos.getContent( { owner: 'qt', @@ -50,12 +54,22 @@ const fetchQNetworkReplyErrorCodeList = async ( github ) => { } ); const commitId = response.sha; - const qnetworkReplyHeaderSource = decodeRepoContent( response ); - const qnetworkReplyErrorCodes = extractQNetworkReplyErrorCodes( qnetworkReplyHeaderSource ); + const qNetworkReplyHeaderSource = decodeRepoContent( response ); + const qNetworkReplyErrorCodes = extractQNetworkReplyErrorCodes( qNetworkReplyHeaderSource ); - return { commitId, qnetworkReplyErrorCodes }; + return { commitId, qNetworkReplyErrorCodes }; }; +const fetchQNetworkReplyErrorCodeListFromQt = async () => { + const response = await fetch( qNetworkReplyHeaderUrl ); + if ( !response.ok ) { + throw Error( `Error fetching QNetworkReply header: ${response.status} ${response.statusText}` ); + } + const qNetworkReplyHeaderSource = await response.text(); + + return extractQNetworkReplyErrorCodes( qNetworkReplyHeaderSource ); +} + const decodeRepoContent = ( response ) => { try { return Buffer.from( response.content, response.encoding ).toString( 'utf-8' ); @@ -66,23 +80,29 @@ const decodeRepoContent = ( response ) => { }; const extractQNetworkReplyErrorCodes = ( qnetworkReplyHeaderSource ) => { - + const enumMatch = /enum NetworkError {(.*?)};/s.exec( qnetworkReplyHeaderSource ); + if ( !enumMatch ) { + throw Error( 'Could not extract NetworkError codes from QNetworkReply header' ); + } + const enums = enumMatch[ 1 ].trim().replace( /\/\/.*$|[ \t]+|\n\n+|,/mg, '' ); + return enums; } -const getDiffWithLastUsedVersion = async ( httpStatusCodeList ) => { - const pathToLastUsedVersion = path.resolve( './.github/http-status-codes.txt' ); +const getDiffWithLastUsedVersion = async ( qNetworkReplyErrorCodes ) => { + const pathToLastUsedVersion = path.resolve( './.github/QNetworkReplyErroCodes.txt' ); const lastUsedVersion = await fs.readFile( pathToLastUsedVersion, { encoding: 'utf-8' } ); - if ( lastUsedVersion === httpStatusCodeList ) { + if ( lastUsedVersion === qNetworkReplyErrorCodes ) { return null; } - const patch = diff.createPatch( 'http-status-codes.txt', lastUsedVersion, httpStatusCodeList ); + const patch = diff.createPatch( 'QNetworkReplyErroCodes.txt', lastUsedVersion, qNetworkReplyErrorCodes ); return patch; }; -const createNewGithubIssue = async ( { diffWithLastUsedVersion, github, context, dryRun } ) => { - const title = `${issueTitleBase} ${lastUpdatedDate}`; +const createNewGithubIssue = async ( { commitId, diffWithLastUsedVersion, github, context, dryRun } ) => { + const commitIdShort = shortenCommitId( commitId ); + const title = `${issueTitleBase} ${commitIdShort}`; const body = 'The `QNetworkReply::NetworkError` codes list has been updated. \n' + - 'See https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml' + '\n\n' + + `See [qnetworkreply.h@${commitIdShort}](https://code.qt.io/cgit/qt/qtbase.git/commit/src/network/access/qnetworkreply.h?id=${commitId})` + '\n\n' + '## Diff ##' + '\n' + '```diff' + '\n' + diffWithLastUsedVersion + '\n' + @@ -100,11 +120,14 @@ const createNewGithubIssue = async ( { diffWithLastUsedVersion, github, context, const main = async () => { try { - const qnetworkReplyErrorCodes = await fetchQNetworkReplyErrorCodeList(); + const qnetworkReplyErrorCodes = await fetchQNetworkReplyErrorCodeListFromQt(); const patch = await getDiffWithLastUsedVersion( qnetworkReplyErrorCodes ); if ( patch ) { log.log( patch ); } + else { + log.log( "Last used version is still up to date!" ); + } } catch( reason ) { log.error( reason ); From 1fd85b9b6debf282c89a3681063a148483c017b6 Mon Sep 17 00:00:00 2001 From: Jochen Ulrich Date: Thu, 16 Jul 2020 00:37:32 +0200 Subject: [PATCH 24/36] Tests checking for QNetworkReply error codes updates --- .github/workflows/checkForCodeUpdates.yml | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/.github/workflows/checkForCodeUpdates.yml b/.github/workflows/checkForCodeUpdates.yml index 9a15de3..0e53232 100644 --- a/.github/workflows/checkForCodeUpdates.yml +++ b/.github/workflows/checkForCodeUpdates.yml @@ -19,3 +19,16 @@ jobs: script: | const path = require( 'path' ); await require( path.resolve( './.github/checkForHttpStatusCodesUpdate.js' ) )( { github, core, context, dryRun: false } ); + + check-qnetworkreply-error-codes-update: + name: Check for QNetworkReply Error Codes Update + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-node@v1 + - run: npm install + - uses: actions/github-script@v2 + with: + script: | + const path = require( 'path' ); + await require( path.resolve( './.github/checkQNetworkReplyErrorCodeUpdate.js' ) )( { github, core, context, dryRun: true } ); From d3ecd47a649b9f47423e9b85bc0cedaff60a645e Mon Sep 17 00:00:00 2001 From: Jochen Ulrich Date: Thu, 16 Jul 2020 00:40:59 +0200 Subject: [PATCH 25/36] Fixes yml syntax error --- .github/workflows/checkForCodeUpdates.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/checkForCodeUpdates.yml b/.github/workflows/checkForCodeUpdates.yml index 0e53232..f4c2805 100644 --- a/.github/workflows/checkForCodeUpdates.yml +++ b/.github/workflows/checkForCodeUpdates.yml @@ -28,7 +28,7 @@ jobs: - uses: actions/setup-node@v1 - run: npm install - uses: actions/github-script@v2 - with: + with: script: | const path = require( 'path' ); await require( path.resolve( './.github/checkQNetworkReplyErrorCodeUpdate.js' ) )( { github, core, context, dryRun: true } ); From f48167dcd321dda38b4fc764a1b84a4dc6837074 Mon Sep 17 00:00:00 2001 From: Jochen Ulrich Date: Thu, 16 Jul 2020 00:48:37 +0200 Subject: [PATCH 26/36] Debugging fetching repo content --- .github/checkQNetworkReplyErrorCodeUpdate.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/checkQNetworkReplyErrorCodeUpdate.js b/.github/checkQNetworkReplyErrorCodeUpdate.js index 8fa1adb..990eadc 100644 --- a/.github/checkQNetworkReplyErrorCodeUpdate.js +++ b/.github/checkQNetworkReplyErrorCodeUpdate.js @@ -45,7 +45,7 @@ const shortenCommitId = commitId => { }; const fetchQNetworkReplyErrorCodeListFromGitHub = async ( github ) => { - + console.log( github.repos ); const response = await github.repos.getContent( { owner: 'qt', repo: 'qtbase', From 56fd0f8874255d96084901ad9caea93896ddb543 Mon Sep 17 00:00:00 2001 From: Jochen Ulrich Date: Thu, 16 Jul 2020 00:53:29 +0200 Subject: [PATCH 27/36] Fixes getContent vs. getContents method name --- .github/checkQNetworkReplyErrorCodeUpdate.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/checkQNetworkReplyErrorCodeUpdate.js b/.github/checkQNetworkReplyErrorCodeUpdate.js index 990eadc..c8ff4b4 100644 --- a/.github/checkQNetworkReplyErrorCodeUpdate.js +++ b/.github/checkQNetworkReplyErrorCodeUpdate.js @@ -45,8 +45,8 @@ const shortenCommitId = commitId => { }; const fetchQNetworkReplyErrorCodeListFromGitHub = async ( github ) => { - console.log( github.repos ); - const response = await github.repos.getContent( { + const getContent = github.repos.getContent || github.repos.getContents; + const response = await getContent( { owner: 'qt', repo: 'qtbase', path: 'src/network/access/qnetworkreply.h', From 4cb645079874cfad8746ed8af0ab4cbf066421e0 Mon Sep 17 00:00:00 2001 From: Jochen Ulrich Date: Thu, 16 Jul 2020 01:02:48 +0200 Subject: [PATCH 28/36] Debugging fetching repo content --- .github/checkQNetworkReplyErrorCodeUpdate.js | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/checkQNetworkReplyErrorCodeUpdate.js b/.github/checkQNetworkReplyErrorCodeUpdate.js index c8ff4b4..1fe928a 100644 --- a/.github/checkQNetworkReplyErrorCodeUpdate.js +++ b/.github/checkQNetworkReplyErrorCodeUpdate.js @@ -72,6 +72,7 @@ const fetchQNetworkReplyErrorCodeListFromQt = async () => { const decodeRepoContent = ( response ) => { try { + console.log( reponse ); return Buffer.from( response.content, response.encoding ).toString( 'utf-8' ); } catch( e ) { From 71e2a918470e71dec335c0b7fa6cd6db89c1c17a Mon Sep 17 00:00:00 2001 From: Jochen Ulrich Date: Thu, 16 Jul 2020 01:03:53 +0200 Subject: [PATCH 29/36] Fixes typo --- .github/checkQNetworkReplyErrorCodeUpdate.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/checkQNetworkReplyErrorCodeUpdate.js b/.github/checkQNetworkReplyErrorCodeUpdate.js index 1fe928a..bf5ef40 100644 --- a/.github/checkQNetworkReplyErrorCodeUpdate.js +++ b/.github/checkQNetworkReplyErrorCodeUpdate.js @@ -72,7 +72,7 @@ const fetchQNetworkReplyErrorCodeListFromQt = async () => { const decodeRepoContent = ( response ) => { try { - console.log( reponse ); + console.log( response ); return Buffer.from( response.content, response.encoding ).toString( 'utf-8' ); } catch( e ) { From be0e168cd7fbdaf0a401f667f1d05a65f8af9e72 Mon Sep 17 00:00:00 2001 From: Jochen Ulrich Date: Thu, 16 Jul 2020 01:06:08 +0200 Subject: [PATCH 30/36] Fixes response handling --- .github/checkQNetworkReplyErrorCodeUpdate.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/checkQNetworkReplyErrorCodeUpdate.js b/.github/checkQNetworkReplyErrorCodeUpdate.js index bf5ef40..367a071 100644 --- a/.github/checkQNetworkReplyErrorCodeUpdate.js +++ b/.github/checkQNetworkReplyErrorCodeUpdate.js @@ -52,9 +52,9 @@ const fetchQNetworkReplyErrorCodeListFromGitHub = async ( github ) => { path: 'src/network/access/qnetworkreply.h', ref: 'dev' } ); - const commitId = response.sha; + const commitId = response.data.sha; - const qNetworkReplyHeaderSource = decodeRepoContent( response ); + const qNetworkReplyHeaderSource = decodeRepoContent( response.data ); const qNetworkReplyErrorCodes = extractQNetworkReplyErrorCodes( qNetworkReplyHeaderSource ); return { commitId, qNetworkReplyErrorCodes }; @@ -72,7 +72,6 @@ const fetchQNetworkReplyErrorCodeListFromQt = async () => { const decodeRepoContent = ( response ) => { try { - console.log( response ); return Buffer.from( response.content, response.encoding ).toString( 'utf-8' ); } catch( e ) { From cdebdfa70481f3ccae360ce2df1f7cdfe43d5da9 Mon Sep 17 00:00:00 2001 From: Jochen Ulrich Date: Thu, 16 Jul 2020 01:07:37 +0200 Subject: [PATCH 31/36] Tests checking for QNetworkReply error codes updates --- .github/QNetworkReplyErroCodes.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/QNetworkReplyErroCodes.txt b/.github/QNetworkReplyErroCodes.txt index 47881e3..b5db5ba 100644 --- a/.github/QNetworkReplyErroCodes.txt +++ b/.github/QNetworkReplyErroCodes.txt @@ -3,6 +3,7 @@ ConnectionRefusedError=1 RemoteHostClosedError HostNotFoundError TimeoutError +something OperationCanceledError SslHandshakeFailedError TemporaryNetworkFailureError From 384ae013055aee8b4375588b923328d9885e84ef Mon Sep 17 00:00:00 2001 From: Jochen Ulrich Date: Thu, 16 Jul 2020 01:12:44 +0200 Subject: [PATCH 32/36] Tests issue creation on QNetworkReply error codes update --- .github/workflows/checkForCodeUpdates.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/checkForCodeUpdates.yml b/.github/workflows/checkForCodeUpdates.yml index f4c2805..029a414 100644 --- a/.github/workflows/checkForCodeUpdates.yml +++ b/.github/workflows/checkForCodeUpdates.yml @@ -31,4 +31,4 @@ jobs: with: script: | const path = require( 'path' ); - await require( path.resolve( './.github/checkQNetworkReplyErrorCodeUpdate.js' ) )( { github, core, context, dryRun: true } ); + await require( path.resolve( './.github/checkQNetworkReplyErrorCodeUpdate.js' ) )( { github, core, context, dryRun: false } ); From f35a64e589b6cb6d2e3fa07c50dffedf42e38639 Mon Sep 17 00:00:00 2001 From: Jochen Ulrich Date: Thu, 16 Jul 2020 01:45:56 +0200 Subject: [PATCH 33/36] Fixes broken link in issue --- .github/checkQNetworkReplyErrorCodeUpdate.js | 25 ++++++++++---------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/.github/checkQNetworkReplyErrorCodeUpdate.js b/.github/checkQNetworkReplyErrorCodeUpdate.js index 367a071..1cbb491 100644 --- a/.github/checkQNetworkReplyErrorCodeUpdate.js +++ b/.github/checkQNetworkReplyErrorCodeUpdate.js @@ -14,7 +14,8 @@ const checkForUpdate = async ( { github, core, context, dryRun } ) => { { log = core; - const { commitId, qNetworkReplyErrorCodes } = await fetchQNetworkReplyErrorCodeListFromGitHub( github ); + const { blobId, qNetworkReplyErrorCodes } = await fetchQNetworkReplyErrorCodeListFromGitHub( github ); + const blobIdShort = shortenId( blobId ); const diffWithLastUsedVersion = await getDiffWithLastUsedVersion( qNetworkReplyErrorCodes ); if ( !diffWithLastUsedVersion ) { log.info( 'QNetworkReply error codes list is still up to date' ); @@ -22,16 +23,16 @@ const checkForUpdate = async ( { github, core, context, dryRun } ) => { } log.warning( 'QNetworkReply error codes list is outdated!' ); - const existingGithubIssues = await githubIssues.searchForExistingGithubIssue( { keywords: [ issueTitleBase, shortenCommitId( commitId ) ], github, context } ); + const existingGithubIssues = await githubIssues.searchForExistingGithubIssue( { keywords: [ issueTitleBase, blobIdShort ], github, context } ); if ( existingGithubIssues.total_count === 0 ) { - createNewGithubIssue( { commitId, diffWithLastUsedVersion, github, context, dryRun } ); + createNewGithubIssue( { blobId, diffWithLastUsedVersion, github, context, dryRun } ); } else if ( existingGithubIssues.total_count === 1 ) { log.info( 'An issue already exists for this update.' ); } else { - log.warning( `Multiple issues exist for the QNetworkReply error codes update with id ${commitId}:\n${ JSON.stringify( existingGithubIssues, undefined, 4 ) }` ); + log.warning( `Multiple issues exist for the QNetworkReply error codes update with id ${blobIdShort}:\n${ JSON.stringify( existingGithubIssues, undefined, 4 ) }` ); } } catch ( error ) { @@ -40,8 +41,8 @@ const checkForUpdate = async ( { github, core, context, dryRun } ) => { } }; -const shortenCommitId = commitId => { - return commitId.substring( 0, 6 ) +const shortenId = id => { + return id.substring( 0, 8 ) }; const fetchQNetworkReplyErrorCodeListFromGitHub = async ( github ) => { @@ -52,12 +53,12 @@ const fetchQNetworkReplyErrorCodeListFromGitHub = async ( github ) => { path: 'src/network/access/qnetworkreply.h', ref: 'dev' } ); - const commitId = response.data.sha; + const blobId = response.data.sha; const qNetworkReplyHeaderSource = decodeRepoContent( response.data ); const qNetworkReplyErrorCodes = extractQNetworkReplyErrorCodes( qNetworkReplyHeaderSource ); - return { commitId, qNetworkReplyErrorCodes }; + return { blobId, qNetworkReplyErrorCodes }; }; const fetchQNetworkReplyErrorCodeListFromQt = async () => { @@ -98,11 +99,11 @@ const getDiffWithLastUsedVersion = async ( qNetworkReplyErrorCodes ) => { return patch; }; -const createNewGithubIssue = async ( { commitId, diffWithLastUsedVersion, github, context, dryRun } ) => { - const commitIdShort = shortenCommitId( commitId ); - const title = `${issueTitleBase} ${commitIdShort}`; +const createNewGithubIssue = async ( { blobId, diffWithLastUsedVersion, github, context, dryRun } ) => { + const blobIdShort = shortenId( blobId ); + const title = `${issueTitleBase} ${blobIdShort}`; const body = 'The `QNetworkReply::NetworkError` codes list has been updated. \n' + - `See [qnetworkreply.h@${commitIdShort}](https://code.qt.io/cgit/qt/qtbase.git/commit/src/network/access/qnetworkreply.h?id=${commitId})` + '\n\n' + + 'See https://code.qt.io/cgit/qt/qtbase.git/log/src/network/access/qnetworkreply.h' + '\n\n' + '## Diff ##' + '\n' + '```diff' + '\n' + diffWithLastUsedVersion + '\n' + From f4e1d9a4ff259daa71f8c4c3399002059d9d4de3 Mon Sep 17 00:00:00 2001 From: Jochen Ulrich Date: Thu, 16 Jul 2020 01:46:44 +0200 Subject: [PATCH 34/36] Removes testing data --- .github/QNetworkReplyErroCodes.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/QNetworkReplyErroCodes.txt b/.github/QNetworkReplyErroCodes.txt index b5db5ba..47881e3 100644 --- a/.github/QNetworkReplyErroCodes.txt +++ b/.github/QNetworkReplyErroCodes.txt @@ -3,7 +3,6 @@ ConnectionRefusedError=1 RemoteHostClosedError HostNotFoundError TimeoutError -something OperationCanceledError SslHandshakeFailedError TemporaryNetworkFailureError From 0d37e6200e3ca08636a08eb1689685a76aa582b4 Mon Sep 17 00:00:00 2001 From: Jochen Ulrich Date: Thu, 16 Jul 2020 01:47:57 +0200 Subject: [PATCH 35/36] Disables checking for udpates on push --- .github/workflows/checkForCodeUpdates.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/checkForCodeUpdates.yml b/.github/workflows/checkForCodeUpdates.yml index 029a414..2c11aba 100644 --- a/.github/workflows/checkForCodeUpdates.yml +++ b/.github/workflows/checkForCodeUpdates.yml @@ -1,7 +1,6 @@ name: Check for Code Updates on: - push: schedule: - cron: '1 * 1 * *' workflow_dispatch: From b8b5fa217f17e0837fc60ac469ccfbea5095c9ba Mon Sep 17 00:00:00 2001 From: Jochen Ulrich Date: Thu, 16 Jul 2020 02:05:09 +0200 Subject: [PATCH 36/36] Removes dummy workflow file --- .github/workflows/ci.yml | 4 ---- 1 file changed, 4 deletions(-) delete mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml deleted file mode 100644 index 8c0341b..0000000 --- a/.github/workflows/ci.yml +++ /dev/null @@ -1,4 +0,0 @@ -name: CI - -on: - workflow_dispatch: