-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Improve fork check in Git hooks installation #268
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
Conversation
The github api, https://api.github.com/repos/${ACCOUNT}/${REPO_NAME}, return with a JSON object like the one below:
{ "id": 944494149, "node_id": "R_kgDOOEvWRQ", "name": "lab0-c_dev", "full_name": "willy-liu/lab0-c_dev", "fork": true, "parent": { "id": 149674932, "node_id": "MDEwOlJlcG9zaXRvcnkxNDk2NzQ5MzI=", "name": "lab0-c", "full_name": "sysprog21/lab0-c", } }
The "fork" value indicates whether the repository is forked from another repository.
If "fork" is true, the API will also return the "parent" field, which contains details of the original repository. We can check .parent.full_name
to verify that this repository is forked from "sysprog21/lab0-c".
However, since grep does not handle JSON format well, I added a jq
installation check after checking for curl installation.
scripts/install-git-hooks
Outdated
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.
Don't do that. The jq
is not required for this case. Use sed/awk instead.
25ef28c
to
eb59173
Compare
- Correct the regular expressions for
ACCOUNT
andREPO_NAME
. - Remove checking the command
jq
- Rewrite jq code with sed/awk.
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.
The homework assignment requires that the repository must always be named lab0-c
. This naming convention serves as a strict identification mechanism to determine who is participating in the assignment.
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.
You should ensure the content retrieved from the curl
command is not empty.
eb59173
to
b22bdf5
Compare
This change enforces that the repository name is "lab0-c" both locally
and on GitHub while ensuring it is correctly forked from
"sysprog21/lab0-c." It validates both the fork status and the parent
repository name using the GitHub API.
Modifications:
- Replaced grep and sed parsing with Git commands and awk for extracting
the repository owner and name. - Added validation to ensure the repository name is "lab0-c."
- Improved fork verification by checking the GitHub API response for both
fork status and parent repository name.
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.
Refine the commit messages to avoid unnecessary bullets for modification items. Always use plain English sentences to describe.
This change ensures that the repository is named "lab0-c" both locally and on GitHub while verifying that it is correctly forked from "sysprog21/lab0-c." The validation now relies on the GitHub API to check both the fork status and the parent repository name. The previous approach using grep and sed for parsing has been replaced with Git commands and awk to extract the repository owner and name. Additional validation ensures the repository name is "lab0-c", and fork verification has been improved by directly analyzing the GitHub API response.
b22bdf5
to
f370589
Compare
Thank @willy-liu for contributing!
This change allows users to modify the repository name when working with a fork.
Modifications:
Note: