-
Notifications
You must be signed in to change notification settings - Fork 1
feat: add GitHub authentication and dotfiles sync functionality #51
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
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
5529c47
feat: add install methods and fix zshrc issue
bniladridas bc86420
feat: add authentication system like huggingface
bniladridas 1e424e1
feat: integrate github oauth authentication
bniladridas 0865b59
feat: add sync and premium features after login
bniladridas d481082
fix: remove unused variables for shellcheck
bniladridas 97d4bd7
Update login.sh
bniladridas eb9f1d9
Update dotfiles-sync.sh
bniladridas 087f5c1
fix: add safety warning and premium
bniladridas db87a57
fix: add pull-requests read permission
bniladridas a41e889
feat: add automated tracking updates
bniladridas 2f69cfb
fix: add github token to workflow
bniladridas e074936
Update auth/login.sh
bniladridas 557db2d
fix: add jq dependency check
bniladridas a5a92c2
fix: remove invalid merged event type
bniladridas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| name: Update Tracking Issue | ||
|
|
||
| on: | ||
| issues: | ||
| types: [opened, closed, reopened] | ||
| pull_request: | ||
| types: [opened, closed, reopened] | ||
|
|
||
| jobs: | ||
| update-tracking: | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| issues: write | ||
| pull-requests: read | ||
| steps: | ||
| - name: Update tracking issue | ||
| uses: actions/github-script@v7 | ||
| with: | ||
| github-token: ${{ secrets.GITHUB_TOKEN }} | ||
| script: | | ||
| const trackingIssueNumber = 52; | ||
|
|
||
| // Get event details | ||
| const { action, number } = context.payload; | ||
| const isIssue = context.eventName === 'issues'; | ||
| const item = context.payload[isIssue ? 'issue' : 'pull_request']; | ||
| const type = isIssue ? 'Issue' : 'PR'; | ||
| const state = item.state; | ||
| const title = item.title; | ||
| const createdAt = new Date(item.created_at).toISOString().split('T')[0]; | ||
|
|
||
| // Format status emoji | ||
| const statusEmoji = state === 'open' ? '🔄' : | ||
| state === 'closed' && !isIssue ? '❌' : | ||
| state === 'merged' ? '🎉' : '✅'; | ||
|
|
||
| // Create update message | ||
| const updateMsg = `## 🤖 Automated Update | ||
|
|
||
| **${type} #${number}** - ${action} | ||
| - **Title**: ${title} | ||
| - **Status**: ${statusEmoji} ${state.toUpperCase()} | ||
| - **Date**: ${createdAt} | ||
| - **Action**: ${action} | ||
|
|
||
| *This tracking issue will be manually updated with full context periodically.*`; | ||
|
|
||
| // Add comment to tracking issue | ||
| await github.rest.issues.createComment({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: trackingIssueNumber, | ||
| body: updateMsg | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| #!/bin/bash | ||
|
|
||
| # GitHub OAuth authentication for dotfiles | ||
| AUTH_DIR="$HOME/.dotfiles" | ||
| TOKEN_FILE="$AUTH_DIR/token" | ||
| USER_FILE="$AUTH_DIR/user" | ||
|
|
||
| log() { | ||
| echo "[$(date +'%Y-%m-%d %H:%M:%S')] $1" | ||
| } | ||
|
|
||
| github_login() { | ||
| # Check for required dependencies | ||
| if ! command -v jq &> /dev/null; then | ||
| log "ERROR: jq is required but not installed" | ||
| exit 1 | ||
| fi | ||
|
|
||
| mkdir -p "$AUTH_DIR" | ||
|
|
||
| log "Opening GitHub OAuth login..." | ||
|
|
||
| # For now, use GitHub personal access token flow | ||
| echo "Please create a GitHub Personal Access Token:" | ||
| echo "1. Go to: https://github.com/settings/tokens" | ||
| echo "2. Click 'Generate new token (classic)'" | ||
| echo "3. Select scopes: repo, user:email" | ||
| echo "4. Copy the generated token" | ||
| echo "" | ||
|
|
||
| open "https://github.com/settings/tokens" 2>/dev/null || \ | ||
| xdg-open "https://github.com/settings/tokens" 2>/dev/null || \ | ||
| echo "Visit: https://github.com/settings/tokens" | ||
|
|
||
| echo "Enter your GitHub token:" | ||
| read -r -s token | ||
|
|
||
| if [ -n "$token" ]; then | ||
| # Validate token with GitHub API | ||
| USER_INFO=$(curl -s -H "Authorization: token $token" https://api.github.com/user) | ||
|
|
||
| USERNAME=$(echo "$USER_INFO" | jq -r '.login') | ||
| if [ -n "$USERNAME" ] && [ "$USERNAME" != "null" ]; then | ||
| echo "$token" > "$TOKEN_FILE" | ||
| echo "$USERNAME" > "$USER_FILE" | ||
| chmod 600 "$TOKEN_FILE" "$USER_FILE" | ||
| log "Successfully logged in as $USERNAME!" | ||
| else | ||
| log "ERROR: Invalid GitHub token" | ||
| exit 1 | ||
| fi | ||
| else | ||
| log "ERROR: No token provided" | ||
| exit 1 | ||
| fi | ||
| } | ||
|
|
||
| logout() { | ||
| if [ -f "$TOKEN_FILE" ]; then | ||
| rm -f "$TOKEN_FILE" "$USER_FILE" | ||
| log "Successfully logged out!" | ||
| else | ||
| log "Not currently logged in" | ||
| fi | ||
| } | ||
|
|
||
| whoami() { | ||
| if [ -f "$TOKEN_FILE" ] && [ -f "$USER_FILE" ]; then | ||
| USERNAME=$(cat "$USER_FILE") | ||
| TOKEN_PREVIEW=$(head -c 8 "$TOKEN_FILE") | ||
| log "Logged in as $USERNAME (token: ${TOKEN_PREVIEW}...)" | ||
| else | ||
| log "Not logged in" | ||
| exit 1 | ||
| fi | ||
| } | ||
|
|
||
| case "$1" in | ||
| login) | ||
| github_login | ||
| ;; | ||
| logout) | ||
| logout | ||
| ;; | ||
| whoami) | ||
| whoami | ||
| ;; | ||
| *) | ||
| echo "Usage: $0 {login|logout|whoami}" | ||
| echo " login - Authenticate with GitHub" | ||
| echo " logout - Remove stored credentials" | ||
| echo " whoami - Show current login status" | ||
| exit 1 | ||
| ;; | ||
| esac | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,142 @@ | ||
| #!/bin/bash | ||
|
|
||
| # Dotfiles sync functionality (requires authentication) | ||
| AUTH_DIR="$HOME/.dotfiles" | ||
| TOKEN_FILE="$AUTH_DIR/token" | ||
| USER_FILE="$AUTH_DIR/user" | ||
| SYNC_REPO="dotfiles-sync" | ||
|
|
||
| log() { | ||
| echo "[$(date +'%Y-%m-%d %H:%M:%S')] $1" | ||
| } | ||
|
|
||
| check_auth() { | ||
| if [ ! -f "$TOKEN_FILE" ] || [ ! -f "$USER_FILE" ]; then | ||
| log "ERROR: Not logged in. Run './auth/login.sh login' first" | ||
| exit 1 | ||
| fi | ||
| } | ||
|
|
||
| sync_push() { | ||
| check_auth | ||
|
|
||
| USERNAME=$(cat "$USER_FILE") | ||
|
|
||
| log "Syncing dotfiles to GitHub..." | ||
|
|
||
| # Create backup of current dotfiles | ||
| BACKUP_DIR="/tmp/dotfiles-backup-$(date +%s)" | ||
| mkdir -p "$BACKUP_DIR" | ||
|
|
||
| # Copy key dotfiles | ||
| [ -f ~/.gitconfig ] && cp ~/.gitconfig "$BACKUP_DIR/" | ||
| [ -f ~/.zshrc ] && cp ~/.zshrc "$BACKUP_DIR/" | ||
| [ -f ~/.bashrc ] && cp ~/.bashrc "$BACKUP_DIR/" | ||
| [ -f ~/.vimrc ] && cp ~/.vimrc "$BACKUP_DIR/" | ||
|
|
||
| # Create or update sync repository | ||
| if ! gh repo view "$USERNAME/$SYNC_REPO" &>/dev/null; then | ||
| log "Creating sync repository..." | ||
| gh repo create "$SYNC_REPO" --private --description "Dotfiles sync backup" | ||
| fi | ||
|
|
||
| # Push to sync repo | ||
| cd "$BACKUP_DIR" || exit 1 | ||
| git init | ||
| git add . | ||
| git commit -m "sync: backup dotfiles $(date)" | ||
| git remote add origin "https://github.com/$USERNAME/$SYNC_REPO.git" | ||
|
|
||
| echo "⚠️ WARNING: This will overwrite the remote sync repository." | ||
| echo "Continue? (y/N): " | ||
| read -r confirm | ||
| if [[ "$confirm" =~ ^[Yy]$ ]]; then | ||
| git push --force-with-lease -u origin main 2>/dev/null || git push -u origin main --force | ||
| else | ||
| log "Sync cancelled by user" | ||
| rm -rf "$BACKUP_DIR" | ||
| exit 1 | ||
| fi | ||
|
|
||
| log "Dotfiles synced to github.com/$USERNAME/$SYNC_REPO" | ||
| rm -rf "$BACKUP_DIR" | ||
| } | ||
|
|
||
| sync_pull() { | ||
| check_auth | ||
|
|
||
| USERNAME=$(cat "$USER_FILE") | ||
|
|
||
| log "Restoring dotfiles from GitHub..." | ||
|
|
||
| # Clone sync repo | ||
| RESTORE_DIR="/tmp/dotfiles-restore-$(date +%s)" | ||
| if gh repo clone "$USERNAME/$SYNC_REPO" "$RESTORE_DIR"; then | ||
| cd "$RESTORE_DIR" || exit 1 | ||
|
|
||
| # Backup existing files | ||
| [ -f ~/.gitconfig ] && cp ~/.gitconfig ~/.gitconfig.backup | ||
| [ -f ~/.zshrc ] && cp ~/.zshrc ~/.zshrc.backup | ||
bniladridas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| [ -f ~/.bashrc ] && cp ~/.bashrc ~/.bashrc.backup | ||
| [ -f ~/.vimrc ] && cp ~/.vimrc ~/.vimrc.backup | ||
|
|
||
| # Restore files | ||
| [ -f .gitconfig ] && cp .gitconfig ~/ | ||
| [ -f .zshrc ] && cp .zshrc ~/ | ||
| [ -f .bashrc ] && cp .bashrc ~/ | ||
| [ -f .vimrc ] && cp .vimrc ~/ | ||
|
|
||
| log "Dotfiles restored from sync repository" | ||
| rm -rf "$RESTORE_DIR" | ||
| else | ||
| log "ERROR: No sync repository found. Run 'sync push' first" | ||
| exit 1 | ||
| fi | ||
| } | ||
|
|
||
| premium_tools() { | ||
| check_auth | ||
|
|
||
| USERNAME=$(cat "$USER_FILE") | ||
| log "Premium tools for $USERNAME:" | ||
| echo " ✓ Advanced linting with custom rules" | ||
| echo " ✓ Team configuration sharing" | ||
| echo " ✓ Automated backup scheduling" | ||
| echo " ✓ Cross-platform sync" | ||
| echo "" | ||
| echo "Note: Premium features are currently in development" | ||
| } | ||
|
|
||
| premium_enable() { | ||
| check_auth | ||
|
|
||
| log "Premium features are currently in development." | ||
| log "Available now: sync push/pull functionality" | ||
| log "Coming soon: Advanced linting, team sharing, automated backups" | ||
| } | ||
|
|
||
| case "$1" in | ||
| push) | ||
| sync_push | ||
| ;; | ||
| pull) | ||
| sync_pull | ||
| ;; | ||
| premium) | ||
| if [ "$2" = "enable" ]; then | ||
| premium_enable | ||
| else | ||
| premium_tools | ||
| fi | ||
| ;; | ||
| *) | ||
| echo "Usage: $0 {push|pull|premium [enable]}" | ||
| echo " push - Backup dotfiles to GitHub" | ||
| echo " pull - Restore dotfiles from GitHub" | ||
| echo " premium - Show premium features" | ||
| echo " premium enable - Enable premium features" | ||
| echo "" | ||
| echo "Note: Requires authentication (./auth/login.sh login)" | ||
| exit 1 | ||
| ;; | ||
| esac | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.