create repo from Template Repo (App Token) #6
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
| name: Fork Template Repo (App Token) | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| template_repo: | |
| description: 'Template repository to fork (e.g. owner/template-repo)' | |
| required: true | |
| default: 'devwithkrishna/enable-codeql-analysis-for-repositories' | |
| target_owner: | |
| description: 'Target org where GitHub App is installed' | |
| required: true | |
| default: 'devwithkrishna' | |
| new_repo_name: | |
| description: 'New name for the forked repository' | |
| required: true | |
| default: 'new-forked-repo' | |
| is_private: | |
| description: 'Make the new repo private? (true/false)' | |
| required: false | |
| default: 'true' | |
| jobs: | |
| fork: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Token generator | |
| uses: githubofkrishnadhas/github-access-using-githubapp@v2 | |
| id: token-generation | |
| with: | |
| github_app_id: ${{ secrets.TOKEN_GENERATOR_APPID }} | |
| github_app_private_key : ${{ secrets.TOKEN_GENERATOR_PRIVATE_KEY }} | |
| - name: Make repo private if required | |
| if: ${{ github.event.inputs.is_private == 'true' }} | |
| env: | |
| GH_APP_TOKEN: ${{ steps.token-generation.outputs.token }} | |
| TARGET_OWNER: "devwithkrishna" | |
| NEW_REPO_NAME: ${{ github.event.inputs.new_repo_name }} | |
| run: | | |
| echo "Setting repository visibility to private..." | |
| curl -L -X POST "https://api.github.com/repos/$TARGET_OWNER/$NEW_REPO_NAME" \ | |
| -H "Authorization: Bearer $GH_APP_TOKEN" \ | |
| -H "Accept: application/vnd.github+json" \ | |
| -d '{"organization":"octocat","name":"Hello-World","private": true}' |