Skip to content

Commit

Permalink
feat: add new exclude_forked input to block forked repos from copy (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
derberg authored Feb 24, 2022
1 parent e48270b commit d5f1d63
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ commit_message | It is used as a commit message when pushing changes with global
repos_to_ignore | Comma-separated list of repositories that should not get updates from this action. Action already ignores the repo in which the action is triggered so you do not need to add it explicitly. In the format `repo1,repo2`. | false | -
topics_to_include | Comma-separated list of topics that should get updates from this action. Repos that do not contain one of the specified topics will get appended to the repos_to_ignore list. In the format `topic1,topic2`. | false | -
exclude_private | Boolean value on whether to exclude private repositories from this action. | false | false
exclude_forked | Boolean value on whether to exclude forked repositories from this action. | false | false

## Examples

Expand Down Expand Up @@ -118,6 +119,7 @@ jobs:
repos_to_ignore: repo1,repo2
topics_to_include: topic1,topic2
exclude_private: true
exclude_forked: true
committer_username: santiago-bernabeu
committer_email: [email protected]
commit_message: "ci: update global workflows"
Expand Down
5 changes: 5 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ inputs:
Boolean value on whether to exclude private repositories from this action.
default: false
required: false
exclude_forked:
description: >
Boolean value on whether to exclude forked repositories from this action.
default: false
required: false
runs:
using: node12
main: dist/index.js
Expand Down
22 changes: 22 additions & 0 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1718,6 +1718,7 @@ async function getRepo(octokit, owner, repo) {
id: data.node_id,
defaultBranch: data.default_branch,
private: data.private,
fork: data.fork,
archived: data.archived,
topics: data.topics,
};
Expand Down Expand Up @@ -1781,6 +1782,7 @@ async function getReposList(octokit, owner) {
id: repo.node_id,
defaultBranch: repo.default_branch,
private: repo.private,
fork: repo.fork,
archived: repo.archived,
topics: repo.topics,
};
Expand Down Expand Up @@ -13398,6 +13400,7 @@ async function run() {
reposToIgnore: core.getInput('repos_to_ignore'),
topicsToInclude: core.getInput('topics_to_include'),
excludePrivate: (core.getInput('exclude_private') === 'true'),
excludeForked: (core.getInput('exclude_forked') === 'true'),
});

/*
Expand Down Expand Up @@ -14546,6 +14549,7 @@ async function getListOfFilesToReplicate(octokit, commitId, owner, repo, filesTo
* @param {String} inputs.reposToIgnore A comma separated list of repositories to ignore.
* @param {String} inputs.topicsToInclude A comma separated list of topics to include.
* @param {Boolean} inputs.excludePrivate Exclude private repositories.
* @param {Boolean} inputs.excludeForked Exclude forked repositories.
*
* @returns {Array}
*/
Expand All @@ -14554,6 +14558,7 @@ function getListOfReposToIgnore(repo, reposList, inputs) {
reposToIgnore,
topicsToInclude,
excludePrivate,
excludeForked,
} = inputs;

core.startGroup('Getting list of repos to be ignored');
Expand All @@ -14580,6 +14585,11 @@ function getListOfReposToIgnore(repo, reposList, inputs) {
ignoredRepositories.push(...privateRepositories(reposList));
}

// Exclude forked repositories
if (excludeForked === true) {
ignoredRepositories.push(...forkedRepositories(reposList));
}

if (!ignoredRepositories.length) {
core.info('No repositories will be ignored.');
} else {
Expand Down Expand Up @@ -14690,6 +14700,18 @@ function privateRepositories(reposList) {
}).map(reposList => reposList.name);
}

/**
* Returns a list of forked repositories.
*
* @param {Array} reposList All the repositories.
* @returns {Array}
*/
function forkedRepositories(reposList) {
return reposList.filter(repo => {
return repo.fork === true;
}).map(reposList => reposList.name);
}

/***/ }),

/***/ 921:
Expand Down
2 changes: 2 additions & 0 deletions lib/api-calls.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ async function getRepo(octokit, owner, repo) {
id: data.node_id,
defaultBranch: data.default_branch,
private: data.private,
fork: data.fork,
archived: data.archived,
topics: data.topics,
};
Expand Down Expand Up @@ -89,6 +90,7 @@ async function getReposList(octokit, owner) {
id: repo.node_id,
defaultBranch: repo.default_branch,
private: repo.private,
fork: repo.fork,
archived: repo.archived,
topics: repo.topics,
};
Expand Down
1 change: 1 addition & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ async function run() {
reposToIgnore: core.getInput('repos_to_ignore'),
topicsToInclude: core.getInput('topics_to_include'),
excludePrivate: (core.getInput('exclude_private') === 'true'),
excludeForked: (core.getInput('exclude_forked') === 'true'),
});

/*
Expand Down
19 changes: 19 additions & 0 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ async function getListOfFilesToReplicate(octokit, commitId, owner, repo, filesTo
* @param {String} inputs.reposToIgnore A comma separated list of repositories to ignore.
* @param {String} inputs.topicsToInclude A comma separated list of topics to include.
* @param {Boolean} inputs.excludePrivate Exclude private repositories.
* @param {Boolean} inputs.excludeForked Exclude forked repositories.
*
* @returns {Array}
*/
Expand All @@ -79,6 +80,7 @@ function getListOfReposToIgnore(repo, reposList, inputs) {
reposToIgnore,
topicsToInclude,
excludePrivate,
excludeForked,
} = inputs;

core.startGroup('Getting list of repos to be ignored');
Expand All @@ -105,6 +107,11 @@ function getListOfReposToIgnore(repo, reposList, inputs) {
ignoredRepositories.push(...privateRepositories(reposList));
}

// Exclude forked repositories
if (excludeForked === true) {
ignoredRepositories.push(...forkedRepositories(reposList));
}

if (!ignoredRepositories.length) {
core.info('No repositories will be ignored.');
} else {
Expand Down Expand Up @@ -213,4 +220,16 @@ function privateRepositories(reposList) {
return reposList.filter(repo => {
return repo.private === true;
}).map(reposList => reposList.name);
}

/**
* Returns a list of forked repositories.
*
* @param {Array} reposList All the repositories.
* @returns {Array}
*/
function forkedRepositories(reposList) {
return reposList.filter(repo => {
return repo.fork === true;
}).map(reposList => reposList.name);
}

0 comments on commit d5f1d63

Please sign in to comment.