diff --git a/.github/GithubAPI.js b/.github/GithubAPI.js index f8adf9d..073fc20 100644 --- a/.github/GithubAPI.js +++ b/.github/GithubAPI.js @@ -1,31 +1,9 @@ -const axios = require("axios"); - module.exports = class GithubAPI { constructor(owner, github) { this.owner = owner; this.github = github; } - async query(query, variables) { - try { - const response = await this.github.graphql( - query, - variables - ); - - console.log("Response", response); - - if (response.data.errors) { - throw new Error(JSON.stringify(response.data.errors, null, 2)); - } - - return response.data; - } catch (error) { - console.error(error); - throw error; - } - } - async getSourceAndTargetProjects({ sourceNumber, targetNumber }) { const projectSubquery = ` id @@ -45,7 +23,7 @@ module.exports = class GithubAPI { `; const query = ` query getSourceAndTargetProjectsIds($owner: String!, $source: Int!, $target: Int!) { - user (login: $owner) { + organization (login: $owner) { source: projectV2(number: $source) { ${projectSubquery} } @@ -56,13 +34,13 @@ module.exports = class GithubAPI { } `; - const response = await this.query(query, { + const response = await this.github.graphql(query, { owner: this.owner, source: sourceNumber, target: targetNumber, }); - const { source, target } = response.data.organization; + const { source, target } = response.organization; if (!source) { throw new Error(`Source project not found: ${sourceNumber}`); @@ -133,24 +111,7 @@ module.exports = class GithubAPI { } `; - const _getProjectItems = async (cursor = null, items = []) => { - const response = await this.query(query, { - projectId, - cursor - }); - - const { nodes, pageInfo } = response.data.node.items; - - items.push(...nodes); - - if (pageInfo.hasNextPage) { - return _getProjectItems(pageInfo.endCursor, items); - } - - return items; - }; - - return _getProjectItems(); + return this.github.graphql.paginate(query, { projectId }); } async updateProjectItemsFields(items) { @@ -173,14 +134,14 @@ module.exports = class GithubAPI { for (let i = 0; i < items.length; i += BATCH_SIZE) { const batch = items.slice(i, i + BATCH_SIZE); - await Promise.all(batch.map(async item => { - await this.query(query, { + await Promise.all(batch.map(item => ( + this.github.graphql(query, { projectId: item.projectId, itemId: item.projectItemId, fieldId: item.fieldId, newValue: item.newValue - }); - })); + }) + ))); } } } \ No newline at end of file diff --git a/.github/githubUtils.js b/.github/githubUtils.js index ae16b2b..e0df143 100644 --- a/.github/githubUtils.js +++ b/.github/githubUtils.js @@ -24,6 +24,7 @@ const synchronizeProjectsStatuses = async (context, github) => { const targetStatusField = targetProject.fields.nodes.find((field) => field.name === "Status"); const targetProjectItems = await githubAPI.getProjectItems(targetProject.id); + console.log("targetProjectItems", targetProjectItems.length) const itemsToUpdate = targetProjectItems.filter((item) => { const statusToByPass = "RELEASED"; const currentTargetStatusName = item.status?.value; diff --git a/.github/workflows/sync_kds_roadmap_statuses.yml b/.github/workflows/sync_kds_roadmap_statuses.yml index f7582c8..7cd24f1 100644 --- a/.github/workflows/sync_kds_roadmap_statuses.yml +++ b/.github/workflows/sync_kds_roadmap_statuses.yml @@ -19,9 +19,6 @@ jobs: with: node-version: '18' - - name: Install axios - run: npm install axios - - uses: tibdex/github-app-token@v1 id: generate-token with: