From a9c4aa93eac9f8d40e1aeb854ff159f5eea851a8 Mon Sep 17 00:00:00 2001 From: "rmotta.net:~#" <114815819+rmottanet@users.noreply.github.com> Date: Wed, 13 Aug 2025 14:58:07 -0300 Subject: [PATCH] Feature: Implements Repository Management Functionality for GitHub Actions (#1) * Github Actions to list repositories * Github Actions to create repositories * Github Actions to delete repositories --- .github/workflows/gh-repo-create.yml | 41 +++++++++++++++++++++++++ .github/workflows/gh-repo-delete.yml | 35 +++++++++++++++++++++ .github/workflows/gh-repo-list-save.yml | 28 +++++++++++++++++ 3 files changed, 104 insertions(+) create mode 100644 .github/workflows/gh-repo-create.yml create mode 100644 .github/workflows/gh-repo-delete.yml create mode 100644 .github/workflows/gh-repo-list-save.yml diff --git a/.github/workflows/gh-repo-create.yml b/.github/workflows/gh-repo-create.yml new file mode 100644 index 0000000..748c4ed --- /dev/null +++ b/.github/workflows/gh-repo-create.yml @@ -0,0 +1,41 @@ +name: Create Repository + +on: + workflow_dispatch: + inputs: + owner_name: + description: 'Github repo owner name.' + required: true + default: 'github' + new_repo_name: + description: 'Github new repo name.' + required: false + default: 'new-repo' + new_repo_description: + description: 'Github repo description.' + required: false + default: 'Some description' + +jobs: + create_repository: + + runs-on: ubuntu-latest + + steps: + - name: Create a new repo + id: create_new_repo + env: + REPO_OWNER_NAME: ${{ github.event.inputs.owner_name }} + NEW_REPO_NAME: ${{ github.event.inputs.new_repo_name }} + NEW_REPO_DESCRIPTION: ${{ github.event.inputs.new_repo_description }} + GH_TOKEN: ${{ secrets.GH_TOKEN }} + run: | + if gh repo create "${REPO_OWNER_NAME}/${NEW_REPO_NAME}" \ + --description "$NEW_REPO_DESCRIPTION" \ + --private; then + echo "::notice::Repository '$NEW_REPO_NAME' created successfully!" + exit 0 + else + echo "::error::Failed to create repository '$NEW_REPO_NAME'." + exit 1 + fi diff --git a/.github/workflows/gh-repo-delete.yml b/.github/workflows/gh-repo-delete.yml new file mode 100644 index 0000000..78d5abd --- /dev/null +++ b/.github/workflows/gh-repo-delete.yml @@ -0,0 +1,35 @@ +name: Delete Repository + +on: + workflow_dispatch: + inputs: + owner_name: + description: 'Github repo owner name.' + required: true + default: 'github' + repo_name: + description: 'Github new repo name.' + required: false + default: 'new-repo' + +jobs: + delete_repository: + + runs-on: ubuntu-latest + + steps: + - name: Delete a new repo + id: delete_repo + env: + REPO_OWNER_NAME: ${{ github.event.inputs.owner_name }} + REPO_NAME: ${{ github.event.inputs.repo_name }} + GH_TOKEN: ${{ secrets.GH_TOKEN }} + run: | + if gh repo delete "${REPO_OWNER_NAME}/${REPO_NAME}" \ + --yes; then + echo "::notice::Repository '$REPO_NAME' deleted successfully!" + exit 0 + else + echo "::error::Failed to create repository '$NEW_REPO_NAME'." + exit 1 + fi diff --git a/.github/workflows/gh-repo-list-save.yml b/.github/workflows/gh-repo-list-save.yml new file mode 100644 index 0000000..e850f7b --- /dev/null +++ b/.github/workflows/gh-repo-list-save.yml @@ -0,0 +1,28 @@ +name: List Repositories and Save + +on: + workflow_dispatch: + inputs: + owner_name: + description: 'Github repo owner name.' + required: true + default: 'github' + limit_output: + description: 'Github repo owner name.' + required: false + default: '100' + +jobs: + list_repos: + runs-on: ubuntu-latest + steps: + - name: List Repositories + run: gh repo list ${{ github.event.inputs.owner_name }} --limit ${{ github.event.inputs.limit_output }} > repositories.txt + env: + GH_TOKEN: ${{ secrets.GH_TOKEN }} + + - name: Save file as artefact + uses: actions/upload-artifact@v4 + with: + name: repositories-list + path: repositories.txt