Skip to content

Commit d7fe973

Browse files
committed
Implements checking for QNetworkReply error codes updates
1 parent 67faab8 commit d7fe973

File tree

2 files changed

+79
-22
lines changed

2 files changed

+79
-22
lines changed

.github/QNetworkReplyErroCodes.txt

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
NoError=0
2+
ConnectionRefusedError=1
3+
RemoteHostClosedError
4+
HostNotFoundError
5+
TimeoutError
6+
OperationCanceledError
7+
SslHandshakeFailedError
8+
TemporaryNetworkFailureError
9+
NetworkSessionFailedError
10+
BackgroundRequestNotAllowedError
11+
TooManyRedirectsError
12+
InsecureRedirectError
13+
UnknownNetworkError=99
14+
ProxyConnectionRefusedError=101
15+
ProxyConnectionClosedError
16+
ProxyNotFoundError
17+
ProxyTimeoutError
18+
ProxyAuthenticationRequiredError
19+
UnknownProxyError=199
20+
ContentAccessDenied=201
21+
ContentOperationNotPermittedError
22+
ContentNotFoundError
23+
AuthenticationRequiredError
24+
ContentReSendError
25+
ContentConflictError
26+
ContentGoneError
27+
UnknownContentError=299
28+
ProtocolUnknownError=301
29+
ProtocolInvalidOperationError
30+
ProtocolFailure=399
31+
InternalServerError=401
32+
OperationNotImplementedError
33+
ServiceUnavailableError
34+
UnknownServerError=499

.github/checkQNetworkReplyErrorCodeUpdate.js

Lines changed: 45 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,37 @@
1+
const fetch = require( 'node-fetch' );
12
const diff = require( 'diff' );
23
const fs = require( 'fs' ).promises;
34
const path = require( 'path' );
45
const githubIssues = require( './githubIssues.js' );
56

67
let log = console;
78

8-
const qnetworkReplyHeaderUrl = 'https://code.qt.io/cgit/qt/qtbase.git/plain/src/network/access/qnetworkreply.h';
9+
const qNetworkReplyHeaderUrl = 'https://code.qt.io/cgit/qt/qtbase.git/plain/src/network/access/qnetworkreply.h';
910
const issueTitleBase = 'QNetworkReply Error Code Update';
1011

1112
const checkForUpdate = async ( { github, core, context, dryRun } ) => {
1213
try
1314
{
1415
log = core;
1516

16-
const qnetworkReplyErrorCodes = await fetchQNetworkReplyErrorCodeList( github );
17-
const lastUpdatedDate = httpStatusCodes.lastUpdated;
18-
const diffWithLastUsedVersion = await getDiffWithLastUsedVersion( httpStatusCodes.httpStatusCodesList );
17+
const { commitId, qNetworkReplyErrorCodes } = await fetchQNetworkReplyErrorCodeListFromGitHub( github );
18+
const diffWithLastUsedVersion = await getDiffWithLastUsedVersion( qNetworkReplyErrorCodes );
1919
if ( !diffWithLastUsedVersion ) {
20-
log.info( 'HTTP status codes list is still up to date' );
20+
log.info( 'QNetworkReply error codes list is still up to date' );
2121
return;
2222
}
23-
log.warning( 'HTTP status codes list is outdated!' );
23+
log.warning( 'QNetworkReply error codes list is outdated!' );
2424

25-
const existingGithubIssues = await githubIssues.searchForExistingGithubIssue( { keywords: [ issueTitleBase, lastUpdatedDate ], github, context } );
25+
const existingGithubIssues = await githubIssues.searchForExistingGithubIssue( { keywords: [ issueTitleBase, shortenCommitId( commitId ) ], github, context } );
2626

2727
if ( existingGithubIssues.total_count === 0 ) {
28-
createNewGithubIssue( { lastUpdatedDate, diffWithLastUsedVersion, github, context, dryRun } );
28+
createNewGithubIssue( { commitId, diffWithLastUsedVersion, github, context, dryRun } );
2929
}
3030
else if ( existingGithubIssues.total_count === 1 ) {
3131
log.info( 'An issue already exists for this update.' );
3232
}
3333
else {
34-
log.warning( `Multiple issues exist for the HTTP status code update from ${lastUpdatedDate}:\n${ JSON.stringify( existingGithubIssues, undefined, 4 ) }` );
34+
log.warning( `Multiple issues exist for the QNetworkReply error codes update with id ${commitId}:\n${ JSON.stringify( existingGithubIssues, undefined, 4 ) }` );
3535
}
3636
}
3737
catch ( error ) {
@@ -40,7 +40,11 @@ const checkForUpdate = async ( { github, core, context, dryRun } ) => {
4040
}
4141
};
4242

43-
const fetchQNetworkReplyErrorCodeList = async ( github ) => {
43+
const shortenCommitId = commitId => {
44+
return commitId.substring( 0, 6 )
45+
};
46+
47+
const fetchQNetworkReplyErrorCodeListFromGitHub = async ( github ) => {
4448

4549
const response = await github.repos.getContent( {
4650
owner: 'qt',
@@ -50,12 +54,22 @@ const fetchQNetworkReplyErrorCodeList = async ( github ) => {
5054
} );
5155
const commitId = response.sha;
5256

53-
const qnetworkReplyHeaderSource = decodeRepoContent( response );
54-
const qnetworkReplyErrorCodes = extractQNetworkReplyErrorCodes( qnetworkReplyHeaderSource );
57+
const qNetworkReplyHeaderSource = decodeRepoContent( response );
58+
const qNetworkReplyErrorCodes = extractQNetworkReplyErrorCodes( qNetworkReplyHeaderSource );
5559

56-
return { commitId, qnetworkReplyErrorCodes };
60+
return { commitId, qNetworkReplyErrorCodes };
5761
};
5862

63+
const fetchQNetworkReplyErrorCodeListFromQt = async () => {
64+
const response = await fetch( qNetworkReplyHeaderUrl );
65+
if ( !response.ok ) {
66+
throw Error( `Error fetching QNetworkReply header: ${response.status} ${response.statusText}` );
67+
}
68+
const qNetworkReplyHeaderSource = await response.text();
69+
70+
return extractQNetworkReplyErrorCodes( qNetworkReplyHeaderSource );
71+
}
72+
5973
const decodeRepoContent = ( response ) => {
6074
try {
6175
return Buffer.from( response.content, response.encoding ).toString( 'utf-8' );
@@ -66,23 +80,29 @@ const decodeRepoContent = ( response ) => {
6680
};
6781

6882
const extractQNetworkReplyErrorCodes = ( qnetworkReplyHeaderSource ) => {
69-
83+
const enumMatch = /enum NetworkError {(.*?)};/s.exec( qnetworkReplyHeaderSource );
84+
if ( !enumMatch ) {
85+
throw Error( 'Could not extract NetworkError codes from QNetworkReply header' );
86+
}
87+
const enums = enumMatch[ 1 ].trim().replace( /\/\/.*$|[ \t]+|\n\n+|,/mg, '' );
88+
return enums;
7089
}
7190

72-
const getDiffWithLastUsedVersion = async ( httpStatusCodeList ) => {
73-
const pathToLastUsedVersion = path.resolve( './.github/http-status-codes.txt' );
91+
const getDiffWithLastUsedVersion = async ( qNetworkReplyErrorCodes ) => {
92+
const pathToLastUsedVersion = path.resolve( './.github/QNetworkReplyErroCodes.txt' );
7493
const lastUsedVersion = await fs.readFile( pathToLastUsedVersion, { encoding: 'utf-8' } );
75-
if ( lastUsedVersion === httpStatusCodeList ) {
94+
if ( lastUsedVersion === qNetworkReplyErrorCodes ) {
7695
return null;
7796
}
78-
const patch = diff.createPatch( 'http-status-codes.txt', lastUsedVersion, httpStatusCodeList );
97+
const patch = diff.createPatch( 'QNetworkReplyErroCodes.txt', lastUsedVersion, qNetworkReplyErrorCodes );
7998
return patch;
8099
};
81100

82-
const createNewGithubIssue = async ( { diffWithLastUsedVersion, github, context, dryRun } ) => {
83-
const title = `${issueTitleBase} ${lastUpdatedDate}`;
101+
const createNewGithubIssue = async ( { commitId, diffWithLastUsedVersion, github, context, dryRun } ) => {
102+
const commitIdShort = shortenCommitId( commitId );
103+
const title = `${issueTitleBase} ${commitIdShort}`;
84104
const body = 'The `QNetworkReply::NetworkError` codes list has been updated. \n' +
85-
'See https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml' + '\n\n' +
105+
`See [qnetworkreply.h@${commitIdShort}](https://code.qt.io/cgit/qt/qtbase.git/commit/src/network/access/qnetworkreply.h?id=${commitId})` + '\n\n' +
86106
'## Diff ##' + '\n' +
87107
'```diff' + '\n' +
88108
diffWithLastUsedVersion + '\n' +
@@ -100,11 +120,14 @@ const createNewGithubIssue = async ( { diffWithLastUsedVersion, github, context,
100120
const main = async () => {
101121
try
102122
{
103-
const qnetworkReplyErrorCodes = await fetchQNetworkReplyErrorCodeList();
123+
const qnetworkReplyErrorCodes = await fetchQNetworkReplyErrorCodeListFromQt();
104124
const patch = await getDiffWithLastUsedVersion( qnetworkReplyErrorCodes );
105125
if ( patch ) {
106126
log.log( patch );
107127
}
128+
else {
129+
log.log( "Last used version is still up to date!" );
130+
}
108131
}
109132
catch( reason ) {
110133
log.error( reason );

0 commit comments

Comments
 (0)