From 7266218ba0ddfd6d73131ce03d4049d65aabf252 Mon Sep 17 00:00:00 2001 From: samad-yar-khan Date: Fri, 25 Mar 2022 13:04:00 +0530 Subject: [PATCH] Gitlab component kit backedn setup --- cms/.env.example | 1 + cms/api/gitlab-issues/config/routes.json | 52 +++ .../controllers/gitlab-issues.js | 8 + cms/api/gitlab-issues/models/gitlab-issues.js | 8 + .../models/gitlab-issues.settings.json | 22 ++ .../gitlab-issues/services/gitlab-issues.js | 8 + cms/api/gitlab-members/config/routes.json | 52 +++ .../controllers/gitlab-members.js | 8 + .../gitlab-members/models/gitlab-members.js | 8 + .../models/gitlab-members.settings.json | 22 ++ .../gitlab-members/services/gitlab-members.js | 8 + .../gitlab-merge-requests/config/routes.json | 52 +++ .../controllers/gitlab-merge-requests.js | 8 + .../models/gitlab-merge-requests.js | 8 + .../gitlab-merge-requests.settings.json | 22 ++ .../services/gitlab-merge-requests.js | 8 + .../gitlab-repositories/config/routes.json | 52 +++ .../controllers/gitlab-repositories.js | 8 + .../models/gitlab-repositories.js | 8 + .../models/gitlab-repositories.settings.json | 33 ++ .../services/gitlab-repositories.js | 8 + cms/config/functions/cron.js | 4 + cms/config/functions/gitlab.js | 302 ++++++++++++++++++ 23 files changed, 710 insertions(+) create mode 100644 cms/api/gitlab-issues/config/routes.json create mode 100644 cms/api/gitlab-issues/controllers/gitlab-issues.js create mode 100644 cms/api/gitlab-issues/models/gitlab-issues.js create mode 100644 cms/api/gitlab-issues/models/gitlab-issues.settings.json create mode 100644 cms/api/gitlab-issues/services/gitlab-issues.js create mode 100644 cms/api/gitlab-members/config/routes.json create mode 100644 cms/api/gitlab-members/controllers/gitlab-members.js create mode 100644 cms/api/gitlab-members/models/gitlab-members.js create mode 100644 cms/api/gitlab-members/models/gitlab-members.settings.json create mode 100644 cms/api/gitlab-members/services/gitlab-members.js create mode 100644 cms/api/gitlab-merge-requests/config/routes.json create mode 100644 cms/api/gitlab-merge-requests/controllers/gitlab-merge-requests.js create mode 100644 cms/api/gitlab-merge-requests/models/gitlab-merge-requests.js create mode 100644 cms/api/gitlab-merge-requests/models/gitlab-merge-requests.settings.json create mode 100644 cms/api/gitlab-merge-requests/services/gitlab-merge-requests.js create mode 100644 cms/api/gitlab-repositories/config/routes.json create mode 100644 cms/api/gitlab-repositories/controllers/gitlab-repositories.js create mode 100644 cms/api/gitlab-repositories/models/gitlab-repositories.js create mode 100644 cms/api/gitlab-repositories/models/gitlab-repositories.settings.json create mode 100644 cms/api/gitlab-repositories/services/gitlab-repositories.js create mode 100644 cms/config/functions/gitlab.js diff --git a/cms/.env.example b/cms/.env.example index b667b6c4..371c3f74 100644 --- a/cms/.env.example +++ b/cms/.env.example @@ -1,2 +1,3 @@ HOST=0.0.0.0 PORT=1337 +GITLAB_TOKEN='gitlab_personal_access_token' \ No newline at end of file diff --git a/cms/api/gitlab-issues/config/routes.json b/cms/api/gitlab-issues/config/routes.json new file mode 100644 index 00000000..8877cf63 --- /dev/null +++ b/cms/api/gitlab-issues/config/routes.json @@ -0,0 +1,52 @@ +{ + "routes": [ + { + "method": "GET", + "path": "/gitlab-issues", + "handler": "gitlab-issues.find", + "config": { + "policies": [] + } + }, + { + "method": "GET", + "path": "/gitlab-issues/count", + "handler": "gitlab-issues.count", + "config": { + "policies": [] + } + }, + { + "method": "GET", + "path": "/gitlab-issues/:id", + "handler": "gitlab-issues.findOne", + "config": { + "policies": [] + } + }, + { + "method": "POST", + "path": "/gitlab-issues", + "handler": "gitlab-issues.create", + "config": { + "policies": [] + } + }, + { + "method": "PUT", + "path": "/gitlab-issues/:id", + "handler": "gitlab-issues.update", + "config": { + "policies": [] + } + }, + { + "method": "DELETE", + "path": "/gitlab-issues/:id", + "handler": "gitlab-issues.delete", + "config": { + "policies": [] + } + } + ] +} diff --git a/cms/api/gitlab-issues/controllers/gitlab-issues.js b/cms/api/gitlab-issues/controllers/gitlab-issues.js new file mode 100644 index 00000000..e8608953 --- /dev/null +++ b/cms/api/gitlab-issues/controllers/gitlab-issues.js @@ -0,0 +1,8 @@ +'use strict'; + +/** + * Read the documentation (https://strapi.io/documentation/developer-docs/latest/development/backend-customization.html#core-controllers) + * to customize this controller + */ + +module.exports = {}; diff --git a/cms/api/gitlab-issues/models/gitlab-issues.js b/cms/api/gitlab-issues/models/gitlab-issues.js new file mode 100644 index 00000000..0054d33c --- /dev/null +++ b/cms/api/gitlab-issues/models/gitlab-issues.js @@ -0,0 +1,8 @@ +'use strict'; + +/** + * Read the documentation (https://strapi.io/documentation/developer-docs/latest/development/backend-customization.html#lifecycle-hooks) + * to customize this model + */ + +module.exports = {}; diff --git a/cms/api/gitlab-issues/models/gitlab-issues.settings.json b/cms/api/gitlab-issues/models/gitlab-issues.settings.json new file mode 100644 index 00000000..2df83084 --- /dev/null +++ b/cms/api/gitlab-issues/models/gitlab-issues.settings.json @@ -0,0 +1,22 @@ +{ + "kind": "collectionType", + "collectionName": "gitlab_issues", + "info": { + "name": "GitlabIssues" + }, + "options": { + "increments": true, + "timestamps": true, + "draftAndPublish": true + }, + "pluginOptions": {}, + "attributes": { + "gitlab_repository": { + "model": "gitlab-repositories", + "via": "gitlab_issue" + }, + "issues": { + "type": "json" + } + } +} diff --git a/cms/api/gitlab-issues/services/gitlab-issues.js b/cms/api/gitlab-issues/services/gitlab-issues.js new file mode 100644 index 00000000..6538a8c8 --- /dev/null +++ b/cms/api/gitlab-issues/services/gitlab-issues.js @@ -0,0 +1,8 @@ +'use strict'; + +/** + * Read the documentation (https://strapi.io/documentation/developer-docs/latest/development/backend-customization.html#core-services) + * to customize this service + */ + +module.exports = {}; diff --git a/cms/api/gitlab-members/config/routes.json b/cms/api/gitlab-members/config/routes.json new file mode 100644 index 00000000..b830ef23 --- /dev/null +++ b/cms/api/gitlab-members/config/routes.json @@ -0,0 +1,52 @@ +{ + "routes": [ + { + "method": "GET", + "path": "/gitlab-members", + "handler": "gitlab-members.find", + "config": { + "policies": [] + } + }, + { + "method": "GET", + "path": "/gitlab-members/count", + "handler": "gitlab-members.count", + "config": { + "policies": [] + } + }, + { + "method": "GET", + "path": "/gitlab-members/:id", + "handler": "gitlab-members.findOne", + "config": { + "policies": [] + } + }, + { + "method": "POST", + "path": "/gitlab-members", + "handler": "gitlab-members.create", + "config": { + "policies": [] + } + }, + { + "method": "PUT", + "path": "/gitlab-members/:id", + "handler": "gitlab-members.update", + "config": { + "policies": [] + } + }, + { + "method": "DELETE", + "path": "/gitlab-members/:id", + "handler": "gitlab-members.delete", + "config": { + "policies": [] + } + } + ] +} diff --git a/cms/api/gitlab-members/controllers/gitlab-members.js b/cms/api/gitlab-members/controllers/gitlab-members.js new file mode 100644 index 00000000..e8608953 --- /dev/null +++ b/cms/api/gitlab-members/controllers/gitlab-members.js @@ -0,0 +1,8 @@ +'use strict'; + +/** + * Read the documentation (https://strapi.io/documentation/developer-docs/latest/development/backend-customization.html#core-controllers) + * to customize this controller + */ + +module.exports = {}; diff --git a/cms/api/gitlab-members/models/gitlab-members.js b/cms/api/gitlab-members/models/gitlab-members.js new file mode 100644 index 00000000..0054d33c --- /dev/null +++ b/cms/api/gitlab-members/models/gitlab-members.js @@ -0,0 +1,8 @@ +'use strict'; + +/** + * Read the documentation (https://strapi.io/documentation/developer-docs/latest/development/backend-customization.html#lifecycle-hooks) + * to customize this model + */ + +module.exports = {}; diff --git a/cms/api/gitlab-members/models/gitlab-members.settings.json b/cms/api/gitlab-members/models/gitlab-members.settings.json new file mode 100644 index 00000000..83a82e95 --- /dev/null +++ b/cms/api/gitlab-members/models/gitlab-members.settings.json @@ -0,0 +1,22 @@ +{ + "kind": "collectionType", + "collectionName": "gitlab_members", + "info": { + "name": "GitlabMembers" + }, + "options": { + "increments": true, + "timestamps": true, + "draftAndPublish": true + }, + "pluginOptions": {}, + "attributes": { + "members": { + "type": "json" + }, + "gitlab_repository": { + "model": "gitlab-repositories", + "via": "gitlab_member" + } + } +} diff --git a/cms/api/gitlab-members/services/gitlab-members.js b/cms/api/gitlab-members/services/gitlab-members.js new file mode 100644 index 00000000..6538a8c8 --- /dev/null +++ b/cms/api/gitlab-members/services/gitlab-members.js @@ -0,0 +1,8 @@ +'use strict'; + +/** + * Read the documentation (https://strapi.io/documentation/developer-docs/latest/development/backend-customization.html#core-services) + * to customize this service + */ + +module.exports = {}; diff --git a/cms/api/gitlab-merge-requests/config/routes.json b/cms/api/gitlab-merge-requests/config/routes.json new file mode 100644 index 00000000..12c1f9bc --- /dev/null +++ b/cms/api/gitlab-merge-requests/config/routes.json @@ -0,0 +1,52 @@ +{ + "routes": [ + { + "method": "GET", + "path": "/gitlab-merge-requests", + "handler": "gitlab-merge-requests.find", + "config": { + "policies": [] + } + }, + { + "method": "GET", + "path": "/gitlab-merge-requests/count", + "handler": "gitlab-merge-requests.count", + "config": { + "policies": [] + } + }, + { + "method": "GET", + "path": "/gitlab-merge-requests/:id", + "handler": "gitlab-merge-requests.findOne", + "config": { + "policies": [] + } + }, + { + "method": "POST", + "path": "/gitlab-merge-requests", + "handler": "gitlab-merge-requests.create", + "config": { + "policies": [] + } + }, + { + "method": "PUT", + "path": "/gitlab-merge-requests/:id", + "handler": "gitlab-merge-requests.update", + "config": { + "policies": [] + } + }, + { + "method": "DELETE", + "path": "/gitlab-merge-requests/:id", + "handler": "gitlab-merge-requests.delete", + "config": { + "policies": [] + } + } + ] +} diff --git a/cms/api/gitlab-merge-requests/controllers/gitlab-merge-requests.js b/cms/api/gitlab-merge-requests/controllers/gitlab-merge-requests.js new file mode 100644 index 00000000..e8608953 --- /dev/null +++ b/cms/api/gitlab-merge-requests/controllers/gitlab-merge-requests.js @@ -0,0 +1,8 @@ +'use strict'; + +/** + * Read the documentation (https://strapi.io/documentation/developer-docs/latest/development/backend-customization.html#core-controllers) + * to customize this controller + */ + +module.exports = {}; diff --git a/cms/api/gitlab-merge-requests/models/gitlab-merge-requests.js b/cms/api/gitlab-merge-requests/models/gitlab-merge-requests.js new file mode 100644 index 00000000..0054d33c --- /dev/null +++ b/cms/api/gitlab-merge-requests/models/gitlab-merge-requests.js @@ -0,0 +1,8 @@ +'use strict'; + +/** + * Read the documentation (https://strapi.io/documentation/developer-docs/latest/development/backend-customization.html#lifecycle-hooks) + * to customize this model + */ + +module.exports = {}; diff --git a/cms/api/gitlab-merge-requests/models/gitlab-merge-requests.settings.json b/cms/api/gitlab-merge-requests/models/gitlab-merge-requests.settings.json new file mode 100644 index 00000000..f71c7696 --- /dev/null +++ b/cms/api/gitlab-merge-requests/models/gitlab-merge-requests.settings.json @@ -0,0 +1,22 @@ +{ + "kind": "collectionType", + "collectionName": "gitlab_merge_requests", + "info": { + "name": "GitlabMergeRequests" + }, + "options": { + "increments": true, + "timestamps": true, + "draftAndPublish": true + }, + "pluginOptions": {}, + "attributes": { + "merges": { + "type": "json" + }, + "gitlab_repository": { + "model": "gitlab-repositories", + "via": "gitlab_merge_request" + } + } +} diff --git a/cms/api/gitlab-merge-requests/services/gitlab-merge-requests.js b/cms/api/gitlab-merge-requests/services/gitlab-merge-requests.js new file mode 100644 index 00000000..6538a8c8 --- /dev/null +++ b/cms/api/gitlab-merge-requests/services/gitlab-merge-requests.js @@ -0,0 +1,8 @@ +'use strict'; + +/** + * Read the documentation (https://strapi.io/documentation/developer-docs/latest/development/backend-customization.html#core-services) + * to customize this service + */ + +module.exports = {}; diff --git a/cms/api/gitlab-repositories/config/routes.json b/cms/api/gitlab-repositories/config/routes.json new file mode 100644 index 00000000..addb3365 --- /dev/null +++ b/cms/api/gitlab-repositories/config/routes.json @@ -0,0 +1,52 @@ +{ + "routes": [ + { + "method": "GET", + "path": "/gitlab-repositories", + "handler": "gitlab-repositories.find", + "config": { + "policies": [] + } + }, + { + "method": "GET", + "path": "/gitlab-repositories/count", + "handler": "gitlab-repositories.count", + "config": { + "policies": [] + } + }, + { + "method": "GET", + "path": "/gitlab-repositories/:id", + "handler": "gitlab-repositories.findOne", + "config": { + "policies": [] + } + }, + { + "method": "POST", + "path": "/gitlab-repositories", + "handler": "gitlab-repositories.create", + "config": { + "policies": [] + } + }, + { + "method": "PUT", + "path": "/gitlab-repositories/:id", + "handler": "gitlab-repositories.update", + "config": { + "policies": [] + } + }, + { + "method": "DELETE", + "path": "/gitlab-repositories/:id", + "handler": "gitlab-repositories.delete", + "config": { + "policies": [] + } + } + ] +} diff --git a/cms/api/gitlab-repositories/controllers/gitlab-repositories.js b/cms/api/gitlab-repositories/controllers/gitlab-repositories.js new file mode 100644 index 00000000..e8608953 --- /dev/null +++ b/cms/api/gitlab-repositories/controllers/gitlab-repositories.js @@ -0,0 +1,8 @@ +'use strict'; + +/** + * Read the documentation (https://strapi.io/documentation/developer-docs/latest/development/backend-customization.html#core-controllers) + * to customize this controller + */ + +module.exports = {}; diff --git a/cms/api/gitlab-repositories/models/gitlab-repositories.js b/cms/api/gitlab-repositories/models/gitlab-repositories.js new file mode 100644 index 00000000..0054d33c --- /dev/null +++ b/cms/api/gitlab-repositories/models/gitlab-repositories.js @@ -0,0 +1,8 @@ +'use strict'; + +/** + * Read the documentation (https://strapi.io/documentation/developer-docs/latest/development/backend-customization.html#lifecycle-hooks) + * to customize this model + */ + +module.exports = {}; diff --git a/cms/api/gitlab-repositories/models/gitlab-repositories.settings.json b/cms/api/gitlab-repositories/models/gitlab-repositories.settings.json new file mode 100644 index 00000000..5883b328 --- /dev/null +++ b/cms/api/gitlab-repositories/models/gitlab-repositories.settings.json @@ -0,0 +1,33 @@ +{ + "kind": "collectionType", + "collectionName": "gitlab_repositories", + "info": { + "name": "GitlabRepositories" + }, + "options": { + "increments": true, + "timestamps": true, + "draftAndPublish": true + }, + "pluginOptions": {}, + "attributes": { + "project_id": { + "type": "string" + }, + "project_data": { + "type": "json" + }, + "gitlab_issue": { + "via": "gitlab_repository", + "model": "gitlab-issues" + }, + "gitlab_member": { + "via": "gitlab_repository", + "model": "gitlab-members" + }, + "gitlab_merge_request": { + "via": "gitlab_repository", + "model": "gitlab-merge-requests" + } + } +} diff --git a/cms/api/gitlab-repositories/services/gitlab-repositories.js b/cms/api/gitlab-repositories/services/gitlab-repositories.js new file mode 100644 index 00000000..6538a8c8 --- /dev/null +++ b/cms/api/gitlab-repositories/services/gitlab-repositories.js @@ -0,0 +1,8 @@ +'use strict'; + +/** + * Read the documentation (https://strapi.io/documentation/developer-docs/latest/development/backend-customization.html#core-services) + * to customize this service + */ + +module.exports = {}; diff --git a/cms/config/functions/cron.js b/cms/config/functions/cron.js index 41a97583..8046245c 100644 --- a/cms/config/functions/cron.js +++ b/cms/config/functions/cron.js @@ -2,6 +2,7 @@ const { getLatestCommunityActivity } = require("./fetchTopPosts"); const { getCommunityContributors } = require("./fetchContributors") const { getGithubIssues, getGithubContributors } = require("./github"); +const { gitlabKit } = require("./gitlab") /** * Cron config that gives you an opportunity * to run scheduled jobs. @@ -29,5 +30,8 @@ module.exports = { '*/0 0 1 * * *': () => { getGithubIssues('RocketChat', 'RC4Community'); getGithubContributors('RocketChat', 'RC4Community'); + }, + '*/20 * * * * *': () => { + gitlabKit(278964,['issues','merges','members']); } }; diff --git a/cms/config/functions/gitlab.js b/cms/config/functions/gitlab.js new file mode 100644 index 00000000..917c31ee --- /dev/null +++ b/cms/config/functions/gitlab.js @@ -0,0 +1,302 @@ +const axios = require('axios'); + +const getRepoData = async function (project_id,token) { + try { + let returnedData = await axios({ + method: 'GET', + url: `https://gitlab.com/api/v4/projects/${project_id}`, + headers: { Authorization: `Bearer ${token}` } + }); + + const { data } = returnedData; + const { + id, + name, + namespace, + name_with_namespace, + http_url_to_repo, + description, + star_count, + forks_count, + open_issues_count, + topics, + } = data; + const html_url = http_url_to_repo; + const ownerName = namespace.name; + const full_name = name_with_namespace; + const compactData = { + id, + full_name, + name, + ownerName, + html_url, + description, + star_count, + forks_count, + open_issues_count, + topics, + }; + return { + success: true, + data: compactData, + }; + } catch (err) { + return { + error_message: err, + success: false, + message: "Internal Server Error!", + }; + } +}; + +const getRepoIssues = async function (project_id,token) { + try { + let returnedData = await axios({ + method: 'GET', + url: `https://gitlab.com/api/v4/projects/${project_id}/issues`, + headers: { Authorization: `Bearer ${token}` } + }); + let data = returnedData.data; + let issueList = []; + + data.forEach((issue)=>{ + let newIssue = new Object(); + if(issue.state === 'opened' ){ + newIssue['id'] = issue.id; + newIssue['author'] = issue.author; + newIssue['title'] = issue.title; + newIssue['iid'] = issue.iid; + newIssue['web_url'] = issue.web_url; + newIssue['created_at'] = issue.created_at; + newIssue['upvotes'] = issue.upvotes; + newIssue['downvotes'] = issue.downvotes; + issueList.push(newIssue); + } + }); + + return { + success: true, + data: issueList, + }; + } catch (err) { + return { + error_message: err, + success: false, + message: "Internal Server Error!", + }; + } +}; + +const getRepoMerges = async function (project_id,token) { + try { + let returnedData = await axios({ + method: 'GET', + url: `https://gitlab.com/api/v4/projects/${project_id}/merge_requests`, + headers: { Authorization: `Bearer ${token}` } + }); + let data = returnedData.data; + + let mergeRequestList = []; + data.forEach((mergeRequest)=>{ + + let newMergeRequest = new Object(); + if(mergeRequest.closed_at === null ){ + newMergeRequest['id'] = mergeRequest.id; + newMergeRequest['author'] = mergeRequest.author; + newMergeRequest['title'] = mergeRequest.title; + newMergeRequest['iid'] = mergeRequest.iid; + newMergeRequest['web_url'] = mergeRequest.web_url; + newMergeRequest['created_at'] = mergeRequest.created_at; + newMergeRequest['upvotes'] = mergeRequest.upvotes; + newMergeRequest['downvotes'] = mergeRequest.downvotes; + mergeRequestList.push(newMergeRequest); + } + }); + return { + success: true, + data: mergeRequestList, + }; + } catch (err) { + return { + error_message: err, + success: false, + message: "Internal Server Error!", + }; + } +}; + +const getProjectMembers = async function (project_id,token) { + try { + let returnedData = await axios({ + method: 'GET', + url: `https://gitlab.com/api/v4/projects/${project_id}/members`, + headers: { Authorization: `Bearer ${token}` } + }); + + const { data } = returnedData; + + + + let contributorList = []; + data.forEach((contributor) => { + let newContributor = new Object(); + newContributor["id"] = contributor.id; + newContributor["web_url"] = contributor.web_url; + newContributor["name"] = contributor.name; + newContributor["username"] = contributor.username; + newContributor["avatar_url"] = contributor.avatar_url; + contributorList.push(newContributor); + }); + + return { + success: true, + data: contributorList, + }; + } catch (err) { + return { + error_message: err, + success: false, + message: "Internal Server Error!", + }; + } +}; + +module.exports.gitlabKit = async function (project_id , needed) { + try { + let getIssues = false; + let getMerges = false; + let getMembers = false; + if (Array.isArray(needed)) { + needed.forEach((need) => { + if (need === "issues") { + getIssues = true; + } else if (need === "merges") { + getMerges = true; + } else if (need === "members") { + getMembers = true; + } + }); + } else { + if (needed === "issues") { + getIssues = true; + } else if (needed === "merges") { + getMerges = true; + } else if (needed === "members") { + getMembers = true; + } + } + const token = process.env.GITLAB_TOKEN; + let repoData = await getRepoData(project_id,token); + + let gitlabRepositoryCount = await strapi + .query("gitlab-repositories") + .count({ + project_id:project_id + }); + let gitlabRepository = await strapi.query("gitlab-repositories").findOne({ + project_id:project_id + }); + + if (repoData.success) { + if (gitlabRepositoryCount === 0) { + gitlabRepository = await strapi.query("gitlab-repositories").create({ + project_id: repoData.data.id, + project_data: repoData.data, + }); + } else { + gitlabRepository.project_data = repoData.data; + gitlabRepository.project_id = repoData.data.id; + await strapi.query("gitlab-repositories").update( + { + id: gitlabRepository.id, + }, + gitlabRepository + ); + } + } + + if (getIssues) { + const issuesData = await getRepoIssues(project_id , token); + + if (issuesData.success) { + const issueCount = await strapi.query("gitlab-issues").count({ + gitlab_repository: gitlabRepository.id, + }); + if (issueCount === 0) { + let newissueData = await strapi.query("gitlab-issues").create({ + gitlab_repository: gitlabRepository.id, + issues: issuesData.data, + }); + issuesId = newissueData.id; + } else { + await strapi.query("gitlab-issues").update( + { + gitlab_repository: gitlabRepository.id, + }, + { + gitlab_repository: gitlabRepository.id, + issues: issuesData.data, + } + ); + } + } + } + + if (getMerges) { + const mergeData = await getRepoMerges(project_id, token); + if (mergeData.success) { + const mergeDataCount = await strapi.query("gitlab-merge-requests").count({ + gitlab_repository: gitlabRepository.id, + }); + if (mergeDataCount === 0) { + await strapi.query("gitlab-merge-requests").create({ + gitlab_repository: gitlabRepository.id, + merges: mergeData.data, + }); + } else { + await strapi.query("gitlab-merge-requests").update( + { + gitlab_repository: gitlabRepository.id, + }, + { + gitlab_repository: gitlabRepository.id, + merges: mergeData.data, + } + ); + } + } + } + + if (getMembers) { + const memberData = await getProjectMembers(project_id, token); + if (memberData.success) { + const membersDataCount = await strapi + .query("gitlab-members") + .count({ + gitlab_repository: gitlabRepository.id, + }); + + if (membersDataCount === 0) { + await strapi + .query("gitlab-members") + .create({ + gitlab_repository: gitlabRepository.id, + members: memberData.data, + }); + } else { + await strapi.query("gitlab-members").update( + { + gitlab_repository: gitlabRepository.id, + }, + { + gitlab_repository: gitlabRepository.id, + members: memberData.data, + } + ); + } + } + } + } catch (err) { + console.log(err); + } +}; \ No newline at end of file