Merge pull request #4 from ewjoachim/v1-beta
This commit is contained in:
@@ -13,16 +13,18 @@ commit_message="${3}"
|
|||||||
dir="$(mktemp -d)"
|
dir="$(mktemp -d)"
|
||||||
cd $dir
|
cd $dir
|
||||||
|
|
||||||
git clone "https://${GITHUB_TOKEN}@github.com/${repo_name}.wiki.git" .
|
git clone "https://x-access-token:${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
|
||||||
|
|||||||
@@ -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)
|
||||||
@@ -56,7 +57,6 @@ class Config:
|
|||||||
GITHUB_BASE_REF: str
|
GITHUB_BASE_REF: str
|
||||||
GITHUB_TOKEN: str
|
GITHUB_TOKEN: str
|
||||||
GITHUB_REPOSITORY: str
|
GITHUB_REPOSITORY: str
|
||||||
GITHUB_HEAD_REF: str
|
|
||||||
GITHUB_REF: str
|
GITHUB_REF: str
|
||||||
BADGE_FILENAME: str = "coverage-comment-badge.json"
|
BADGE_FILENAME: str = "coverage-comment-badge.json"
|
||||||
COVERAGE_FILE: str = "coverage.xml"
|
COVERAGE_FILE: str = "coverage.xml"
|
||||||
@@ -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,7 +200,9 @@ 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)
|
||||||
return repo.default_branch == config.GITHUB_HEAD_REF
|
|
||||||
|
branch = config.GITHUB_BRANCH_NAME
|
||||||
|
return repo.default_branch == branch
|
||||||
|
|
||||||
|
|
||||||
def post_comment(body: str, gh: github.Github, config: Config) -> None:
|
def post_comment(body: str, gh: github.Github, config: Config) -> None:
|
||||||
@@ -245,9 +254,8 @@ def get_badge_json_url(config: Config) -> str:
|
|||||||
|
|
||||||
def get_previous_coverage_rate(config: Config) -> Optional[float]:
|
def get_previous_coverage_rate(config: Config) -> Optional[float]:
|
||||||
try:
|
try:
|
||||||
return float(
|
response = requests.get(get_badge_json_url(config=config))
|
||||||
requests.get(get_badge_json_url(config=config)).json()["value"][:-1]
|
return float(response.json()["message"][:-1]) / 100
|
||||||
)
|
|
||||||
except Exception:
|
except Exception:
|
||||||
print("Previous coverage results not found, cannot report on evolution.")
|
print("Previous coverage results not found, cannot report on evolution.")
|
||||||
return None
|
return None
|
||||||
|
|||||||
Reference in New Issue
Block a user