From be988c0800eea3a73306222829c7f28a162f5af2 Mon Sep 17 00:00:00 2001 From: Javier <10879637+javiertuya@users.noreply.github.com> Date: Thu, 10 Oct 2024 22:31:11 +0200 Subject: [PATCH] Config options to include forked repos 105 --- dashgit-web/app/Config.js | 2 ++ dashgit-web/app/ConfigController.js | 8 ++++++++ dashgit-web/app/ConfigView.js | 14 +++++++++++++- dashgit-web/app/GitHubApi.js | 7 ++++++- 4 files changed, 29 insertions(+), 2 deletions(-) diff --git a/dashgit-web/app/Config.js b/dashgit-web/app/Config.js index b73b4b5..e9a119d 100644 --- a/dashgit-web/app/Config.js +++ b/dashgit-web/app/Config.js @@ -108,6 +108,8 @@ const config = { this.setDefault(element, "unassignedAdditionalOwner", []); this.setDefault(element, "dependabotAdditionalOwner", []); this.setDefault(element, "graphql", {}); + this.setDefault(element.graphql, "includeForks", false); + this.setDefault(element.graphql, "onlyForks", false); this.setDefault(element.graphql, "ownerAffiliations", ["OWNER"]); this.setDefault(element.graphql, "maxProjects", 20); this.setDefault(element.graphql, "maxBranches", 10); diff --git a/dashgit-web/app/ConfigController.js b/dashgit-web/app/ConfigController.js index e78274e..39ef324 100644 --- a/dashgit-web/app/ConfigController.js +++ b/dashgit-web/app/ConfigController.js @@ -46,6 +46,14 @@ $(document).on('change', '[id^="config-providers-surrogate-enabled-"]', function configView.refreshProviderSurrogate(this, $(this).is(':checked')); }); +// Only one of these checkboxes can be checked +$(document).on('change', '[id^="config-graphql-include-forks-"]', function (e) { + configView.refreshGraphqlIncludeForks(this, $(this).is(':checked')); +}); +$(document).on('change', '[id^="config-graphql-only-forks-"]', function (e) { + configView.refreshGraphqlOnlyForks(this, $(this).is(':checked')); +}); + // Data update events $(document).on('click', '.config-btn-provider-submit', function (e) { diff --git a/dashgit-web/app/ConfigView.js b/dashgit-web/app/ConfigView.js index 9a3058d..04e6937 100644 --- a/dashgit-web/app/ConfigView.js +++ b/dashgit-web/app/ConfigView.js @@ -128,7 +128,9 @@ const configView = { ${provider.provider == "GitLab" ? this.input2html(`config-graphql-maxPipelines-${key}`, "number", "Max pipelines", provider.graphql.maxPipelines, 'required min="2" max="100"', "150", "100", "Maximum number of pipeline runs that are retrieved for each repository/project to get the branches and statuses") - : (this.raw2html("API scope", "Specifies the scope of the GitHub GraphQL API requests that get the branches and statuses") + "   " + : this.check2html(`config-graphql-include-forks-${key}`, "Include Forks", provider.graphql.includeForks) + + this.check2html(`config-graphql-only-forks-${key}`, "Only Forks", provider.graphql.onlyForks) + + (this.raw2html(" - API scope:", "Specifies the scope of the GitHub GraphQL API requests that get the branches and statuses") + "   " + this.check2html(`config-graphql-scope-owner-${key}`, "Owner", provider.graphql.ownerAffiliations.includes("OWNER")) + this.check2html(`config-graphql-scope-organization-${key}`, "Organization member", provider.graphql.ownerAffiliations.includes("ORGANIZATION_MEMBER")) + this.check2html(`config-graphql-scope-collaborator-${key}`, "Collaborator", provider.graphql.ownerAffiliations.includes("COLLABORATOR"))) @@ -211,6 +213,8 @@ const configView = { if (provider.provider == "GitLab") { provider.graphql.maxPipelines = $(`#config-graphql-maxPipelines-${id}`).val().trim(); } else { + provider.graphql.onlyForks = $(`#config-graphql-only-forks-${id}`).is(':checked') + provider.graphql.includeForks = $(`#config-graphql-include-forks-${id}`).is(':checked'); provider.graphql.ownerAffiliations = []; if ($(`#config-graphql-scope-owner-${id}`).is(':checked')) provider.graphql.ownerAffiliations.push("OWNER"); @@ -288,6 +292,14 @@ const configView = { $(providerRoot).find(".config-providers-surrogate-settings").hide(); } }, + refreshGraphqlIncludeForks: function (check, checked) { + if (checked) + $(check).closest(".config-provider-card").find('input[id^="config-graphql-only-forks-"]').prop("checked", false); + }, + refreshGraphqlOnlyForks: function (check, checked) { + if (checked) + $(check).closest(".config-provider-card").find('input[id^="config-graphql-include-forks-"]').prop("checked", false); + }, countUrls: function (providerRoot) { // how many urls match the providerRoot url let count = 0; let urlValue = $(providerRoot).find('input[id^="config-providers-url-"]').val() diff --git a/dashgit-web/app/GitHubApi.js b/dashgit-web/app/GitHubApi.js index 71894b4..257dc54 100644 --- a/dashgit-web/app/GitHubApi.js +++ b/dashgit-web/app/GitHubApi.js @@ -178,10 +178,15 @@ const gitHubApi = { getStatusesQuery: function (provider, maxProjects, includeAll) { let affiliations = provider.graphql.ownerAffiliations.toString(); + let forks = "isFork:false, "; + if (provider.graphql.includeForks) + forks = ""; + else if (provider.graphql.onlyForks) + forks = "isFork:true, "; return `{ viewer { login, resourcePath, url, repositories(first: ${maxProjects}, ownerAffiliations: [${affiliations}], - isFork:false, orderBy: {field: PUSHED_AT, direction: DESC}) { + ${forks} orderBy: {field: PUSHED_AT, direction: DESC}) { nodes { name, nameWithOwner, url, pushedAt ${includeAll ? this.getProjectsRefsSubquery(provider) : ""}