Skip to content
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

Automate repo creation for contributors #906

Open
v1gnesh opened this issue Nov 12, 2024 · 0 comments
Open

Automate repo creation for contributors #906

v1gnesh opened this issue Nov 12, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@v1gnesh
Copy link
Collaborator

v1gnesh commented Nov 12, 2024

Feature Title

autorepo

Feature Description & Current Pain Points

Currently, when someone wants to work on a thingport, a zopen admin has to manually create a repo and setup the necessary access to the new repo for the contributor.

With GH actions and a new issue template, this can be automated.

Proposed Solution & Expected Behavior

Haven't checked if this exact code works but it uses actions/github-script and GH CLI.

issue-template.yaml:

name: Trigger Repository Creation
description: Use this template to request a new repository based on specific criteria.
title: "Create new repo for [Project Name]"
labels: ["repo-creation-request"]
body:
  - type: markdown
    attributes:
      value: |
        ### Guidelines
        - Use this template to request a new repository where the project name should be included in the title.
        - **Important**: Include the word "Trigger" in the title to activate the automation.

  - type: textarea
    id: repo-name
    attributes:
      label: Repository Name
      description: Please enter the desired name for the new repository.
      placeholder: Example: my-new-project
    validations:
      required: true

  - type: textarea
    id: description
    attributes:
      label: Description
      description: Describe the purpose or content of the repository.
    validations:
      required: false

create-repo:

name: Create Repository Based on Issue

on:
  issues:
    types: [opened, labeled]

jobs:
  check_issue:
    runs-on: ubuntu-latest
    if: contains(github.event.issue.title, 'Trigger')
    steps:
      - name: Check if issue contains the trigger word
        run: echo "Issue contains 'Trigger'. Proceeding with review request."

  add_reviewer:
    runs-on: ubuntu-latest
    needs: check_issue
    steps:
      - name: Add Reviewer
        uses: actions/github-script@v6
        with:
          github-token: ${{secrets.GITHUB_TOKEN}}
          script: |
            github.rest.issues.addAssignees({
              issue_number: context.issue.number,
              assignees: ['x']
            })

  create_repo:
    runs-on: ubuntu-latest
    needs: add_reviewer
    if: ${{ github.event.action == 'labeled' && github.event.label.name == 'approved' }}
    steps:
      - name: Parse Issue for Repo Name
        id: parse
        uses: actions/github-script@v6
        with:
          github-token: ${{secrets.GITHUB_TOKEN}}
          script: |
            const issueBody = context.payload.issue.body;
            const repoNameMatch = issueBody.match(/Repository Name:\s*([^\n\r]+)/m);
            if (repoNameMatch) {
              return repoNameMatch[1].trim();
            }
            throw new Error('Repository name not found in issue body');

      - name: Create repository
        env:
          REPO_NAME: ${{ steps.parse.outputs.result }}
          GH_TOKEN: ${{ secrets.GITHUB_PAT }}
        run: |
          gh repo create orgo/$REPO_NAME --public --description "New repo created via automation"
          gh api -X PUT /repos/orgo/$REPO_NAME/collaborators/${{ github.event.issue.user.login }} -f permission=admin

Environment Details (Optional)

No response

Additional Information (Optional)

No response

@v1gnesh v1gnesh added the enhancement New feature or request label Nov 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant