Skip to content

Commit

Permalink
Config options to include forked repos 105
Browse files Browse the repository at this point in the history
  • Loading branch information
javiertuya committed Oct 11, 2024
1 parent 59142f2 commit 9f3ddcf
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 4 deletions.
2 changes: 2 additions & 0 deletions dashgit-web/app/Config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 8 additions & 0 deletions dashgit-web/app/ConfigController.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
14 changes: 13 additions & 1 deletion dashgit-web/app/ConfigView.js
Original file line number Diff line number Diff line change
Expand Up @@ -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")))
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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()
Expand Down
7 changes: 6 additions & 1 deletion dashgit-web/app/GitHubApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) : ""}
Expand Down
4 changes: 2 additions & 2 deletions dashgit-web/test/TestConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe("TestConfig - Sanitizing config data", async function () {
statusSurrogateUser: "",
filterIfLabel: '', unassignedAdditionalOwner: [], dependabotAdditionalOwner: [],
updates: { tokenSecret: "", userEmail: "" },
graphql: { ownerAffiliations: ['OWNER'], maxProjects: 20, maxBranches: 10 }
graphql: { "includeForks": false, "onlyForks": false, ownerAffiliations: ['OWNER'], maxProjects: 20, maxBranches: 10 }
}]
};
assert.deepEqual(expected, config.parseAndSanitizeData(`{ "statusCacheUpdateTime": 60, "providers": [{"provider":"GitHub"}] }`));
Expand All @@ -53,7 +53,7 @@ describe("TestConfig - Sanitizing config data", async function () {
statusSurrogateUser: "",
filterIfLabel: 'lbl', unassignedAdditionalOwner: [], dependabotAdditionalOwner: ["org1", "org2"],
updates: { tokenSecret: "DASHGIT_GITHUB_USER_TOKEN", userEmail: "" },
graphql: { ownerAffiliations: ['OWNER', 'ORGANIZATION_MEMBER'], maxProjects: 10, maxBranches: 20 }
graphql: { "includeForks": false, "onlyForks": false, ownerAffiliations: ['OWNER', 'ORGANIZATION_MEMBER'], maxProjects: 10, maxBranches: 20 }
}]
};
assert.deepEqual(expected, config.parseAndSanitizeData(JSON.stringify(expected)));
Expand Down

0 comments on commit 9f3ddcf

Please sign in to comment.