()
| 50 | |
| 51 | export class GithubQueriesModule extends BaseModule<GithubQueryResults | void> { |
| 52 | override async retrieveData() { |
| 53 | // Non-null assertion is used here as the check for undefined immediately follows to confirm the |
| 54 | // assertion. Typescript's type filtering does not seem to work as needed to understand |
| 55 | // whether githubQueries is undefined or not. |
| 56 | let queries = this.config.caretaker?.githubQueries!; |
| 57 | if (queries === undefined || queries.length === 0) { |
| 58 | Log.debug('No github queries defined in the configuration, skipping'); |
| 59 | return; |
| 60 | } |
| 61 | |
| 62 | /** The results of the generated github query. */ |
| 63 | const queryResult = await this.git.github.graphql(this.buildGraphqlQuery(queries)); |
| 64 | const results = Object.values(queryResult); |
| 65 | |
| 66 | const {owner, name: repo} = this.git.remoteConfig; |
| 67 | |
| 68 | return results.map((result, i) => { |
| 69 | const query = queries[i]; |
| 70 | const queryURLParam = encodeURIComponent(query.query); |
| 71 | |
| 72 | return { |
| 73 | queryName: query.name, |
| 74 | count: result.issueCount, |
| 75 | queryUrl: `https://github.com/${owner}/${repo}/issues?q=${queryURLParam}`, |
| 76 | matchedUrls: result.nodes.map((node) => node.url), |
| 77 | }; |
| 78 | }); |
| 79 | } |
| 80 | |
| 81 | /** Build a Graphql query statement for the provided queries. */ |
| 82 | private buildGraphqlQuery(queries: NonNullable<CaretakerConfig['githubQueries']>) { |
nothing calls this directly
no test coverage detected