Skip to content

Commit fa4a7bc

Browse files
authored
Fix action + update test case (#570)
* Fix action + update test case - Set outputrepo as not required in the GitHub Action definition - Test case: check update of README file with _Used by_ badge * [MegaLinter] Apply linters fixes :) * Fix --------- Co-authored-by: Nicolas Vuillamy <[email protected]> Co-authored-by: nvuillam <[email protected]>
1 parent fe671e7 commit fa4a7bc

File tree

6 files changed

+26
-6
lines changed

6 files changed

+26
-6
lines changed

.github/workflows/github-dependents-info.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636

3737
# Collect data & generate markdown
3838
- name: GitHub Dependents Info
39-
uses: nvuillam/[email protected].2 # If you trust me enough you can replace version by "main" :)
39+
uses: nvuillam/[email protected].3 # If you trust me enough you can replace version by "main" :)
4040
# See documentation for variables details: https://github.com/nvuillam/github-dependents-info?tab=readme-ov-file#%EF%B8%8F-usage
4141
with:
4242
repo: ${{ github.repository }}

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
88

99
- Add your updates here :)
1010

11+
## [1.6.3] 2023-03-03
12+
13+
- Set outputrepo as not required in the GitHub Action definition
14+
- Test case: check update of README file with _Used by_ badge
15+
1116
## [1.6.2] 2023-02-26
1217

1318
- Fix issue with hyperlink when outputrepo is not set

action.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ inputs:
77
required: true
88
outputrepo:
99
description: "Owner and name of the output repository, if different from repo (example: nvuillam/node-sarif-builder)"
10-
required: true
10+
required: false
1111
markdownfile:
1212
description: "Path and name of the output markdown file"
1313
required: false
@@ -31,7 +31,7 @@ inputs:
3131

3232
runs:
3333
using: "docker"
34-
image: "docker://nvuillam/github-dependents-info:v1.6.2"
34+
image: "docker://nvuillam/github-dependents-info:v1.6.3"
3535
args:
3636
- --repo
3737
- ${{ inputs.repo }}

github_dependents_info/gh_dependents_info.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class GithubDependentsInfo:
1616
def __init__(self, repo, **options) -> None:
1717
self.repo = repo
1818
self.outputrepo = self.repo if "outputrepo" not in options else options["outputrepo"]
19-
if self.outputrepo is None or self.outputrepo == "":
19+
if self.outputrepo is None or self.outputrepo == "" or len(self.outputrepo) < 4:
2020
self.outputrepo = self.repo
2121
self.url_init = f"https://github.com/{self.repo}/network/dependents"
2222
self.url_starts_with = f"/{self.repo}/network/dependents" + "?package_id="
@@ -192,7 +192,8 @@ def collect(self):
192192
if self.doc_url is not None:
193193
doc_url_to_use = self.doc_url
194194
elif self.markdown_file is not None:
195-
doc_url_to_use = f"https://github.com/{self.outputrepo}/blob/main/{self.markdown_file}"
195+
repo_url_part = self.outputrepo if "/" in self.outputrepo else self.repo
196+
doc_url_to_use = f"https://github.com/{repo_url_part}/blob/main/{self.markdown_file}"
196197
self.badges["total_doc_url"] = self.build_badge("Used%20by", self.total_sum, url=doc_url_to_use)
197198

198199
self.badges["total"] = self.build_badge("Used%20by", self.total_sum)

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ build-backend = "poetry.core.masonry.api"
55

66
[tool.poetry]
77
name = "github-dependents-info"
8-
version = "1.6.2"
8+
version = "1.6.3"
99
description = "Collect information about dependencies between a github repo and other repositories. Results available in JSON, markdown and badges."
1010
readme = "README.md"
1111
authors = ["nvuillam <[email protected]>"]

tests/test_gh_dependents_info/test_gh_dependents_info.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99

1010
def test_collect_stats_single_package():
11+
# Check generate single package stats file
1112
repo = "nvuillam/npm-groovy-lint"
1213
tmp_md_file = tempfile.gettempdir() + os.path.sep + str(uuid.uuid4()) + "-test-single.md"
1314
gh_deps_info = GithubDependentsInfo(
@@ -22,6 +23,19 @@ def test_collect_stats_single_package():
2223
with open(tmp_md_file, encoding="utf-8") as file:
2324
md_content = file.read()
2425
assert md_content.count("\n") > 10
26+
# Check Update README file
27+
tmp_readme_file = tempfile.gettempdir() + os.path.sep + str(uuid.uuid4()) + "-test-single-readme.md"
28+
with open(tmp_readme_file, "w", encoding="utf-8") as file:
29+
file.write(
30+
"<!-- gh-dependents-info-used-by-start -->" + "shouldBeReplaced" + "<!-- gh-dependents-info-used-by-end -->"
31+
)
32+
33+
gh_deps_info.badges["total_doc_url"] = "https://nvuillam/npm-groovy-lint"
34+
gh_deps_info.write_badge(tmp_readme_file, "total_doc_url")
35+
with open(tmp_readme_file, encoding="utf-8") as file:
36+
readme_content = file.read()
37+
assert "shouldBeReplaced" not in readme_content
38+
assert "nvuillam/npm-groovy-lint" in readme_content
2539

2640

2741
def test_collect_stats_multi_package():

0 commit comments

Comments
 (0)