-
Notifications
You must be signed in to change notification settings - Fork 1
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
Get best-fitting branch name of a given repo based on current branch name (on current repo) action #12
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: JesusPoderoso <[email protected]>
@@ -0,0 +1,63 @@ | |||
name: 'get_branch' | |||
description: 'Get the branch name of the given repository that fits with the given repo@branch' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, explain a bit more the logic of the algorithm
description: 'Reference to Git current' | ||
required: true | ||
|
||
remote_repository: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NIT;
remote_repository: | |
source_repository: |
It does not need to be remote, is it?
run: | | ||
echo "::group::Get the branch name of ${{ inputs.remote_repository }}" | ||
echo "using head '${{ inputs.head_ref }}' branch" | ||
DOC_REPO=https://github.com/eProsima/${{ remote_repository }}.git |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use user/repo_name
as repository name, and not only the name.
This is how is done in other internal and external actions (e.g. https://github.com/actions/checkout#usage)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This also helps you to use this action with variable $GITHUB_REPOSITORY
that retrieves the info of "this" repo in user/name format
RESPONSE_CODE=$(git ls-remote --heads $DOC_REPO ${{ inputs.base_ref }} | wc -l) | ||
if [[ ${RESPONSE_CODE} == "0" ]] | ||
then | ||
echo "base '${{ inputs.base_ref }}' branch DOES NOT exist, using 'MASTER'" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if what you are looking for is the default branch (main
, master
or whatever) use this:
curl -s "https://api.github.com/repos/${{ inputs.remote_repository }}" | jq -r '.default_branch'
Check:
https://dev.to/bowmanjd/get-github-default-branch-from-the-command-line-powershell-or-bash-zsh-37m9
|
||
- name: get_branch | ||
run: | | ||
echo "::group::Get the branch name of ${{ inputs.remote_repository }}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
echo "::group::Get the branch name of ${{ inputs.remote_repository }}" | |
echo "::group::Get the branch name of ${{ inputs.remote_repository }}" | |
Please, keep same format as other actions when possible
description: 'Environment Variable name for result' | ||
required: true | ||
|
||
head_ref: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume head and base are used here as arguments because of where this action will be used from.
I would change these names for attempt1 attempt2
or something different that has no meaning itself (head and base has meaning in git already, and it is not the same as the meaning used here).
Let's be pythonic, the function does not depend on where it is called. Who calls it dependens on the function. 🔫
INPUTS:
LOGICS:
this feature has not been tested deeply yet