Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
2ca4a36
Excludes .github files from .gitignore and adds npm files
j-ulrich Jul 9, 2020
b99c126
Adds scripts to check for HTTP status codes updates
j-ulrich Jul 9, 2020
a5ff6e7
Adds package.json for development of GitHub actions
j-ulrich Jul 9, 2020
f8b6613
Enables Github action on push for development
j-ulrich Jul 9, 2020
64e04a6
Adds status log message
j-ulrich Jul 9, 2020
938f9d0
Testing Github action
j-ulrich Jul 9, 2020
921edfe
Uses context instead of hard coded repo information
j-ulrich Jul 10, 2020
c22d4d7
Tests script
j-ulrich Jul 10, 2020
0cd4e7d
Fixes context access
j-ulrich Jul 10, 2020
f637d37
Fixes context access
j-ulrich Jul 10, 2020
7c00ec4
Debugging issue search
j-ulrich Jul 10, 2020
cae840d
Fixes issue search result handling
j-ulrich Jul 10, 2020
e70752d
Fixes output printing
j-ulrich Jul 10, 2020
4a012ff
Improves output printing
j-ulrich Jul 10, 2020
aada465
Fixes output printing
j-ulrich Jul 10, 2020
20c8331
Fixes missing date in issue body
j-ulrich Jul 10, 2020
34091c5
Disables dryRun
j-ulrich Jul 10, 2020
2b8c69a
Fixes undefined fields
j-ulrich Jul 10, 2020
1718ace
Improves logging
j-ulrich Jul 10, 2020
b1bec00
Re-enables checks after testing
j-ulrich Jul 10, 2020
9a335c9
Refactors check script
Jul 10, 2020
67faab8
WIP: Adds script to check for QNetworkReply error code uodate
Jul 10, 2020
d7fe973
Implements checking for QNetworkReply error codes updates
j-ulrich Jul 15, 2020
1fd85b9
Tests checking for QNetworkReply error codes updates
j-ulrich Jul 15, 2020
d3ecd47
Fixes yml syntax error
j-ulrich Jul 15, 2020
f48167d
Debugging fetching repo content
j-ulrich Jul 15, 2020
56fd0f8
Fixes getContent vs. getContents method name
j-ulrich Jul 15, 2020
4cb6450
Debugging fetching repo content
j-ulrich Jul 15, 2020
71e2a91
Fixes typo
j-ulrich Jul 15, 2020
be0e168
Fixes response handling
j-ulrich Jul 15, 2020
cdebdfa
Tests checking for QNetworkReply error codes updates
j-ulrich Jul 15, 2020
384ae01
Tests issue creation on QNetworkReply error codes update
j-ulrich Jul 15, 2020
f35a64e
Fixes broken link in issue
j-ulrich Jul 15, 2020
f4e1d9a
Removes testing data
j-ulrich Jul 15, 2020
0d37e62
Disables checking for udpates on push
j-ulrich Jul 15, 2020
0952ac2
Merge branch 'master' into feature/7-check-for-code-updates
j-ulrich Jul 16, 2020
b8b5fa2
Removes dummy workflow file
j-ulrich Jul 16, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions .github/QNetworkReplyErroCodes.txt
Original file line number Diff line number Diff line change
@@ -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
107 changes: 107 additions & 0 deletions .github/checkForHttpStatusCodesUpdate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
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
{
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;
}
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 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 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 ( { 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
{
const httpStatusCodes = await fetchHttpStatusCodesList();
log.log( httpStatusCodes.lastUpdated );
const patch = await getDiffWithLastUsedVersion( httpStatusCodes.httpStatusCodesList );
if ( patch ) {
log.log( patch );
}
}
catch( reason ) {
log.error( reason );
process.exitCode = -1;
};
};

module.exports = checkForUpdate;

if ( require.main === module ) {
main();
}
143 changes: 143 additions & 0 deletions .github/checkQNetworkReplyErrorCodeUpdate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
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 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 { 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' );
return;
}
log.warning( 'QNetworkReply error codes list is outdated!' );

const existingGithubIssues = await githubIssues.searchForExistingGithubIssue( { keywords: [ issueTitleBase, blobIdShort ], github, context } );

if ( existingGithubIssues.total_count === 0 ) {
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 ${blobIdShort}:\n${ JSON.stringify( existingGithubIssues, undefined, 4 ) }` );
}
}
catch ( error ) {
core.setFailed( `Could not check for HTTP status codes updates: ${error}` );
throw error;
}
};

const shortenId = id => {
return id.substring( 0, 8 )
};

const fetchQNetworkReplyErrorCodeListFromGitHub = async ( github ) => {
const getContent = github.repos.getContent || github.repos.getContents;
const response = await getContent( {
owner: 'qt',
repo: 'qtbase',
path: 'src/network/access/qnetworkreply.h',
ref: 'dev'
} );
const blobId = response.data.sha;

const qNetworkReplyHeaderSource = decodeRepoContent( response.data );
const qNetworkReplyErrorCodes = extractQNetworkReplyErrorCodes( qNetworkReplyHeaderSource );

return { blobId, 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' );
}
catch( e ) {
throw Error( `Unsupported repository content encoding: ${response.encoding}\nOriginal exception: ${e}` );
}
};

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 ( qNetworkReplyErrorCodes ) => {
const pathToLastUsedVersion = path.resolve( './.github/QNetworkReplyErroCodes.txt' );
const lastUsedVersion = await fs.readFile( pathToLastUsedVersion, { encoding: 'utf-8' } );
if ( lastUsedVersion === qNetworkReplyErrorCodes ) {
return null;
}
const patch = diff.createPatch( 'QNetworkReplyErroCodes.txt', lastUsedVersion, qNetworkReplyErrorCodes );
return patch;
};

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 https://code.qt.io/cgit/qt/qtbase.git/log/src/network/access/qnetworkreply.h' + '\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 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 );
process.exitCode = -1;
};
};

module.exports = checkForUpdate;

if ( require.main === module ) {
main();
}
23 changes: 23 additions & 0 deletions .github/githubIssues.js
Original file line number Diff line number Diff line change
@@ -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 };
Loading