Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix way of collecting git branch names #570

Merged
merged 4 commits into from
Jul 10, 2023

Conversation

Konboi
Copy link
Contributor

@Konboi Konboi commented Jul 3, 2023

We used git rev-parse --abbrev-ref HEAD to collect a git branch name. However, in detached HEAD case, this command couldn't get a collect branch name and got HEAD. e.g) https://stackoverflow.com/questions/6059336/how-to-find-the-current-git-branch-in-detached-head-state

So, we changed to use environment variables that each CI provider provides and git show-ref | grep '^'$(git rev-parse HEAD)

@Konboi Konboi force-pushed the fix-collect-git-branch-name-command branch from 32c8612 to 59721fc Compare July 5, 2023 08:30
@Konboi Konboi changed the title wip Fix way of collecting git branch names Jul 10, 2023
@Konboi Konboi force-pushed the fix-collect-git-branch-name-command branch from 494dcfa to 89c0365 Compare July 10, 2023 01:35
@Konboi Konboi force-pushed the fix-collect-git-branch-name-command branch from 89c0365 to cdd3263 Compare July 10, 2023 01:42
@Konboi Konboi requested a review from shibuiwilliam July 10, 2023 02:51
@@ -248,3 +248,46 @@ def build(ctx: click.core.Context, build_name: str, source: List[str], max_days:
))

write_build(build_name)


def _get_branch_name(repo_dist: str) -> Optional[str]:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[question]
When does this return None?
I see the code may return "", but cannot determine None.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know your opinion but if I changed Optional[str] to str , these errors will happen

$ pipenv run type
launchable/commands/record/build.py:260: error: Incompatible return value type (got "Optional[str]", expected "str")  [return-value]
launchable/commands/record/build.py:262: error: Incompatible return value type (got "Optional[str]", expected "str")  [return-value]
launchable/commands/record/build.py:267: error: Incompatible return value type (got "Optional[str]", expected "str")  [return-value]
launchable/commands/record/build.py:269: error: Incompatible return value type (got "Optional[str]", expected "str")  [return-value]
launchable/commands/record/build.py:274: error: Incompatible return value type (got "Optional[str]", expected "str")  [return-value]

Copy link
Contributor Author

@Konboi Konboi Jul 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which is better 1. Keep Optional[str] 2. Change to return os.environ.get(JENKINS_GIT_BRANCH_KEY, "")?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you are checking the env var existence in the code, then I think you can just return os.environ["KEY"].
This should return str for value of env var dict.

I suppose it is better to avoid None (or nil in Go, Null in Java) than accept None if possible.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! I fixed it e448da1

Copy link
Contributor

@shibuiwilliam shibuiwilliam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one question.

@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@basil
Copy link
Contributor

basil commented Jul 13, 2023

Causes #581.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants