-
Notifications
You must be signed in to change notification settings - Fork 4
Feature: Add GitHub Repository Transfer Capability #23
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,58 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| #!/usr/bin/env bash | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| set -eo pipefail | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Authentication and configuration | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| # The script follows the project architecture, locating the base directory to load utilities. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| BASE_DIR=$(dirname "$(readlink -f "$0")")/.. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| source "${BASE_DIR}/utils/settings.sh" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Ensures GITHUB_TOKEN is available, loading auth.sh if necessary | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| # This allows the script to run standalone | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| if [[ -z "${GITHUB_TOKEN:-}" ]]; then | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| if [[ -f "${BASE_DIR}/utils/auth.sh" ]]; then | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| source "${BASE_DIR}/utils/auth.sh" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Function to transfer a repository on GitHub | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| function transfer_github_repo() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| local target_repo | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| local new_owner | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| local endpoint | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| local payload | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| local response | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Target repository in owner/repo format | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| target_repo="$1" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| # New owner (user or organization) for the repository | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| new_owner="$2" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Basic parameter validation | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| if [[ -z "$target_repo" || -z "$new_owner" ]]; then | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo "Usage: $0 <owner/repo> <novo_owner>" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| exit 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+31
to
+34
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The usage message is currently printed to standard output instead of standard error. Additionally, there is a typo in the placeholder (
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Endpoint hardcoded | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Doc: POST /repos/{owner}/{repo}/transfer | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| # https://docs.github.com/en/rest/repos/repos?apiVersion=2026-03-10#transfer-a-repository | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| endpoint="https://api.github.com/repos/$target_repo/transfer" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Creation of the JSON payload for the transfer | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| payload=$(printf '{"new_owner":"%s"}' "$new_owner") | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Constructing JSON payloads using string interpolation or
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Performs the transfer using curl. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| response=$(curl --proto "=https" --tlsv1.2 -sSf -L -X POST "$endpoint" \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| -H "Accept: application/vnd.github+json" \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| -H "Authorization: Bearer $GITHUB_TOKEN" \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| -H "X-GitHub-Api-Version: 2026-03-10" \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| -d "$payload") | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Displays the response message or the repository name upon success. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo "$response" | jq -r '.message // .name' | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| return 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+45
to
+54
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Script execution with parameters passed via CLI | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| transfer_github_repo "$1" "$2" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
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
GITHUB_TOKENis still unset after attempting to loadauth.sh, the script will proceed and fail during the API call. Adding an explicit check and exiting early with a clear error message improves the user experience and script robustness.