1- const fetch = require ( 'node-fetch' ) ;
21const diff = require ( 'diff' ) ;
32const fs = require ( 'fs' ) . promises ;
4- const path = require ( 'path' ) ;
5- const githubIssues = require ( './githubIssues.js' ) ;
3+ const githubIssues = require ( './githubIssues' ) ;
4+ const {
5+ fetchQNetworkReplyErrorCodeListFromGitHub,
6+ fetchQNetworkReplyErrorCodeListFromQt,
7+ qNetworkReplyErrorCodesFilePath,
8+ qNetworkReplyErrorCodesFileName
9+ } = require ( './qNetworkReplyErrorCodes' ) ;
610
711let log = console ;
812
9- const qNetworkReplyHeaderUrl = 'https://code.qt.io/cgit/qt/qtbase.git/plain/src/network/access/qnetworkreply.h' ;
1013const issueTitleBase = 'QNetworkReply Error Code Update' ;
1114
1215const checkForUpdate = async ( { github, core, context, dryRun } ) => {
@@ -45,57 +48,14 @@ const shortenId = id => {
4548 return id . substring ( 0 , 8 )
4649} ;
4750
48- const fetchQNetworkReplyErrorCodeListFromGitHub = async ( github ) => {
49- const getContent = github . repos . getContent || github . repos . getContents ;
50- const response = await getContent ( {
51- owner : 'qt' ,
52- repo : 'qtbase' ,
53- path : 'src/network/access/qnetworkreply.h' ,
54- ref : 'dev'
55- } ) ;
56- const blobId = response . data . sha ;
57-
58- const qNetworkReplyHeaderSource = decodeRepoContent ( response . data ) ;
59- const qNetworkReplyErrorCodes = extractQNetworkReplyErrorCodes ( qNetworkReplyHeaderSource ) ;
60-
61- return { blobId, qNetworkReplyErrorCodes } ;
62- } ;
63-
64- const fetchQNetworkReplyErrorCodeListFromQt = async ( ) => {
65- const response = await fetch ( qNetworkReplyHeaderUrl ) ;
66- if ( ! response . ok ) {
67- throw Error ( `Error fetching QNetworkReply header: ${ response . status } ${ response . statusText } ` ) ;
68- }
69- const qNetworkReplyHeaderSource = await response . text ( ) ;
70-
71- return extractQNetworkReplyErrorCodes ( qNetworkReplyHeaderSource ) ;
72- }
73-
74- const decodeRepoContent = ( response ) => {
75- try {
76- return Buffer . from ( response . content , response . encoding ) . toString ( 'utf-8' ) ;
77- }
78- catch ( e ) {
79- throw Error ( `Unsupported repository content encoding: ${ response . encoding } \nOriginal exception: ${ e } ` ) ;
80- }
81- } ;
82-
83- const extractQNetworkReplyErrorCodes = ( qnetworkReplyHeaderSource ) => {
84- const enumMatch = / e n u m N e t w o r k E r r o r { ( .* ?) } ; / s. exec ( qnetworkReplyHeaderSource ) ;
85- if ( ! enumMatch ) {
86- throw Error ( 'Could not extract NetworkError codes from QNetworkReply header' ) ;
87- }
88- const enums = enumMatch [ 1 ] . trim ( ) . replace ( / \/ \/ .* $ | [ \t ] + | \n \n + | , / mg, '' ) ;
89- return enums ;
90- }
9151
9252const getDiffWithLastUsedVersion = async ( qNetworkReplyErrorCodes ) => {
93- const pathToLastUsedVersion = path . resolve ( './.github/QNetworkReplyErroCodes.txt' ) ;
53+ const pathToLastUsedVersion = qNetworkReplyErrorCodesFilePath ;
9454 const lastUsedVersion = await fs . readFile ( pathToLastUsedVersion , { encoding : 'utf-8' } ) ;
9555 if ( lastUsedVersion === qNetworkReplyErrorCodes ) {
9656 return null ;
9757 }
98- const patch = diff . createPatch ( 'QNetworkReplyErroCodes.txt' , lastUsedVersion , qNetworkReplyErrorCodes ) ;
58+ const patch = diff . createPatch ( qNetworkReplyErrorCodesFileName , lastUsedVersion , qNetworkReplyErrorCodes ) ;
9959 return patch ;
10060} ;
10161
@@ -108,7 +68,7 @@ const createNewGithubIssue = async ( { blobId, diffWithLastUsedVersion, github,
10868 '```diff' + '\n' +
10969 diffWithLastUsedVersion + '\n' +
11070 '```' ;
111-
71+
11272 if ( dryRun ) {
11373 log . info ( `Would create issue:\n${ JSON . stringify ( { title, body } , null , 4 ) } ` ) ;
11474 }
@@ -121,8 +81,8 @@ const createNewGithubIssue = async ( { blobId, diffWithLastUsedVersion, github,
12181const main = async ( ) => {
12282 try
12383 {
124- const qnetworkReplyErrorCodes = await fetchQNetworkReplyErrorCodeListFromQt ( ) ;
125- const patch = await getDiffWithLastUsedVersion ( qnetworkReplyErrorCodes ) ;
84+ const qNetworkReplyErrorCodes = await fetchQNetworkReplyErrorCodeListFromQt ( ) ;
85+ const patch = await getDiffWithLastUsedVersion ( qNetworkReplyErrorCodes ) ;
12686 if ( patch ) {
12787 log . log ( patch ) ;
12888 }
@@ -140,4 +100,4 @@ module.exports = checkForUpdate;
140100
141101if ( require . main === module ) {
142102 main ( ) ;
143- }
103+ }
0 commit comments