Skip to content

Commit

Permalink
fix: remove duplicated repositories from list of repos to iterate over (
Browse files Browse the repository at this point in the history
#7)

Co-authored-by: Lukasz Gornicki <lpgornicki@gmail.com>
  • Loading branch information
BOLT04 and derberg authored Sep 1, 2021
1 parent f971ff2 commit 6ddf3cd
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ GitHub Action that handles automated update of dependencies in package.json betw
- [Configuration](#configuration)
- [Example](#example)
- [Development](#development)
- [Debug](#debug)

<!-- tocstop -->

Expand Down Expand Up @@ -96,4 +97,8 @@ jobs:
# GITHUB_REPOSITORY provide name of org/user and the repo in which this workflow is suppose to run
# PACKAGE_JSON_LOC=test is a path to package.json file against you want to test
GITHUB_TOKEN=token PACKAGE_JSON_LOC=test GITHUB_REPOSITORY="lukasz-lab/.github" npm start
```
```

## Debug

In case something ain't right, the action doesn't work as expected, enable debugging. Add to **Secrets** of the repository a secret called `ACTIONS_STEP_DEBUG` with value `true`. Now, once you run the action again, there will be additional logs visible that start with `DEBUG: `.
12 changes: 10 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1826,8 +1826,12 @@ async function getReposList(octokit, name, owner) {
const { data: { items } } = await octokit.search.code({
q: `"${name}" user:${owner} in:file filename:package.json`
});

let processedRepo = {};
// filter() returns only the repos that are not present in processedRepo object, and adds them there to the list
const deduplicatedReposList = items.filter(({ repository: { id }}) => !processedRepo[id] && (processedRepo[id] = true));

return items;
return deduplicatedReposList;
}

async function createPr(octokit, branchName, id, commitMessage, defaultBranch) {
Expand Down Expand Up @@ -1867,6 +1871,7 @@ async function getRepoDefaultBranch(octokit, repo, owner) {
return default_branch;
}


/***/ }),

/***/ 126:
Expand Down Expand Up @@ -11444,6 +11449,9 @@ async function run() {
ignoredRepositories.push(repo);

const reposList = await getReposList(octokit, dependencyName, owner);
core.debug('DEBUG: List of all repost returned by search without duplicates:');
core.debug(JSON.stringify(reposList, null, 2));

const foundReposAmount = reposList.length;
if (!foundReposAmount) return core.info(`No dependants found. No version bump performed. Looks like you do not use ${dependencyName} in your organization :man_shrugging:`);

Expand Down Expand Up @@ -14429,4 +14437,4 @@ function forEach(text, handler) {

/***/ })

/******/ });
/******/ });
8 changes: 6 additions & 2 deletions lib/api-calls.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@ async function getReposList(octokit, name, owner) {
const { data: { items } } = await octokit.search.code({
q: `"${name}" user:${owner} in:file filename:package.json`
});

let processedRepo = {};
// filter() returns only the repos that are not present in processedRepo object, and adds them there to the list
const deduplicatedReposList = items.filter(({ repository: { id }}) => !processedRepo[id] && (processedRepo[id] = true));

return items;
return deduplicatedReposList;
}

async function createPr(octokit, branchName, id, commitMessage, defaultBranch) {
Expand Down Expand Up @@ -43,4 +47,4 @@ async function getRepoDefaultBranch(octokit, repo, owner) {
});

return default_branch;
}
}
3 changes: 3 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ async function run() {
ignoredRepositories.push(repo);

const reposList = await getReposList(octokit, dependencyName, owner);
core.debug('DEBUG: List of all repost returned by search without duplicates:');
core.debug(JSON.stringify(reposList, null, 2));

const foundReposAmount = reposList.length;
if (!foundReposAmount) return core.info(`No dependants found. No version bump performed. Looks like you do not use ${dependencyName} in your organization :man_shrugging:`);

Expand Down

0 comments on commit 6ddf3cd

Please sign in to comment.