Fix diff detection on wiki

This commit is contained in:
Joachim Jablon
2021-09-26 02:30:25 +02:00
parent 77d040cbed
commit 724ba0557a
2 changed files with 15 additions and 8 deletions

View File

@@ -16,13 +16,15 @@ cd $dir
git clone "https://${GITHUB_TOKEN}@github.com/${repo_name}.wiki.git" . git clone "https://${GITHUB_TOKEN}@github.com/${repo_name}.wiki.git" .
echo $stdin > "${filename}" echo $stdin > "${filename}"
if ! git diff --exit-code git add "${filename}"
then
git add "${filename}"
if ! git diff --staged --exit-code
then
git config --global user.email "coverage-comment-action" git config --global user.email "coverage-comment-action"
git config --global user.name "Coverage Comment Action" git config --global user.name "Coverage Comment Action"
git commit -m "$commit_message" git commit -m "$commit_message"
git push -u origin git push -u origin
else
echo "No change detected, skipping."
fi fi

View File

@@ -25,6 +25,7 @@ def main():
config = Config.from_environ(os.environ) config = Config.from_environ(os.environ)
coverage_info = get_coverage_info(config=config) coverage_info = get_coverage_info(config=config)
gh = get_api(config=config) gh = get_api(config=config)
print(f"Operating on {config.GITHUB_REF}")
if config.GITHUB_PR_NUMBER: if config.GITHUB_PR_NUMBER:
print(f"Commenting on the coverage on PR {config.GITHUB_PR_NUMBER}") print(f"Commenting on the coverage on PR {config.GITHUB_PR_NUMBER}")
diff_coverage_info = get_diff_coverage_info(config=config) diff_coverage_info = get_diff_coverage_info(config=config)
@@ -38,7 +39,6 @@ def main():
) )
post_comment(body=comment, gh=gh, config=config) post_comment(body=comment, gh=gh, config=config)
print(config.BADGE_ENABLED, is_main_branch(gh=gh, config=config))
if config.BADGE_ENABLED and is_main_branch(gh=gh, config=config): if config.BADGE_ENABLED and is_main_branch(gh=gh, config=config):
print("Running on default branch, saving Badge into the repo wiki") print("Running on default branch, saving Badge into the repo wiki")
badge = compute_badge(coverage_info=coverage_info, config=config) badge = compute_badge(coverage_info=coverage_info, config=config)
@@ -90,6 +90,13 @@ class Config:
return int(self.GITHUB_REF.split("/")[2]) return int(self.GITHUB_REF.split("/")[2])
return None return None
@property
def GITHUB_BRANCH_NAME(self) -> Optional[str]:
# "refs/pull/2/merge"
if self.GITHUB_REF.startswith("refs/heads/"):
return self.GITHUB_REF.split("/")[-1]
return None
@classmethod @classmethod
def from_environ(cls, environ): def from_environ(cls, environ):
possible_variables = [e for e in inspect.signature(cls).parameters] possible_variables = [e for e in inspect.signature(cls).parameters]
@@ -193,10 +200,8 @@ def get_markdown_comment(
def is_main_branch(gh: github.Github, config: Config) -> bool: def is_main_branch(gh: github.Github, config: Config) -> bool:
repo = gh.get_repo(config.GITHUB_REPOSITORY) repo = gh.get_repo(config.GITHUB_REPOSITORY)
# refs/heads/<branch_name>
if not config.GITHUB_REF.startswith("refs/heads/"): branch = config.GITHUB_BRANCH_NAME
return False
branch = config.GITHUB_REF.split("/")[-1]
return repo.default_branch == branch return repo.default_branch == branch