Skip to content

Commit

Permalink
Fix action + update test case (#570)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
3 people authored Mar 3, 2024
1 parent fe671e7 commit fa4a7bc
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/github-dependents-info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:

# Collect data & generate markdown
- name: GitHub Dependents Info
uses: nvuillam/[email protected].2 # If you trust me enough you can replace version by "main" :)
uses: nvuillam/[email protected].3 # If you trust me enough you can replace version by "main" :)
# See documentation for variables details: https://github.com/nvuillam/github-dependents-info?tab=readme-ov-file#%EF%B8%8F-usage
with:
repo: ${{ github.repository }}
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

- Add your updates here :)

## [1.6.3] 2023-03-03

- Set outputrepo as not required in the GitHub Action definition
- Test case: check update of README file with _Used by_ badge

## [1.6.2] 2023-02-26

- Fix issue with hyperlink when outputrepo is not set
Expand Down
4 changes: 2 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ inputs:
required: true
outputrepo:
description: "Owner and name of the output repository, if different from repo (example: nvuillam/node-sarif-builder)"
required: true
required: false
markdownfile:
description: "Path and name of the output markdown file"
required: false
Expand All @@ -31,7 +31,7 @@ inputs:

runs:
using: "docker"
image: "docker://nvuillam/github-dependents-info:v1.6.2"
image: "docker://nvuillam/github-dependents-info:v1.6.3"
args:
- --repo
- ${{ inputs.repo }}
Expand Down
5 changes: 3 additions & 2 deletions github_dependents_info/gh_dependents_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class GithubDependentsInfo:
def __init__(self, repo, **options) -> None:
self.repo = repo
self.outputrepo = self.repo if "outputrepo" not in options else options["outputrepo"]
if self.outputrepo is None or self.outputrepo == "":
if self.outputrepo is None or self.outputrepo == "" or len(self.outputrepo) < 4:
self.outputrepo = self.repo
self.url_init = f"https://github.com/{self.repo}/network/dependents"
self.url_starts_with = f"/{self.repo}/network/dependents" + "?package_id="
Expand Down Expand Up @@ -192,7 +192,8 @@ def collect(self):
if self.doc_url is not None:
doc_url_to_use = self.doc_url
elif self.markdown_file is not None:
doc_url_to_use = f"https://github.com/{self.outputrepo}/blob/main/{self.markdown_file}"
repo_url_part = self.outputrepo if "/" in self.outputrepo else self.repo
doc_url_to_use = f"https://github.com/{repo_url_part}/blob/main/{self.markdown_file}"
self.badges["total_doc_url"] = self.build_badge("Used%20by", self.total_sum, url=doc_url_to_use)

self.badges["total"] = self.build_badge("Used%20by", self.total_sum)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ build-backend = "poetry.core.masonry.api"

[tool.poetry]
name = "github-dependents-info"
version = "1.6.2"
version = "1.6.3"
description = "Collect information about dependencies between a github repo and other repositories. Results available in JSON, markdown and badges."
readme = "README.md"
authors = ["nvuillam <[email protected]>"]
Expand Down
14 changes: 14 additions & 0 deletions tests/test_gh_dependents_info/test_gh_dependents_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@


def test_collect_stats_single_package():
# Check generate single package stats file
repo = "nvuillam/npm-groovy-lint"
tmp_md_file = tempfile.gettempdir() + os.path.sep + str(uuid.uuid4()) + "-test-single.md"
gh_deps_info = GithubDependentsInfo(
Expand All @@ -22,6 +23,19 @@ def test_collect_stats_single_package():
with open(tmp_md_file, encoding="utf-8") as file:
md_content = file.read()
assert md_content.count("\n") > 10
# Check Update README file
tmp_readme_file = tempfile.gettempdir() + os.path.sep + str(uuid.uuid4()) + "-test-single-readme.md"
with open(tmp_readme_file, "w", encoding="utf-8") as file:
file.write(
"<!-- gh-dependents-info-used-by-start -->" + "shouldBeReplaced" + "<!-- gh-dependents-info-used-by-end -->"
)

gh_deps_info.badges["total_doc_url"] = "https://nvuillam/npm-groovy-lint"
gh_deps_info.write_badge(tmp_readme_file, "total_doc_url")
with open(tmp_readme_file, encoding="utf-8") as file:
readme_content = file.read()
assert "shouldBeReplaced" not in readme_content
assert "nvuillam/npm-groovy-lint" in readme_content


def test_collect_stats_multi_package():
Expand Down

0 comments on commit fa4a7bc

Please sign in to comment.