Skip to content

Commit

Permalink
Create Issue Branch
Browse files Browse the repository at this point in the history
  • Loading branch information
lsiecker committed Oct 11, 2023
1 parent ba81770 commit 3977b9c
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Create Branches for Existing Issues

on:
workflow_dispatch: # This event allows manual triggering of the workflow

jobs:
create-branches:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: 14 # You can adjust the Node.js version as needed

- name: Install dependencies
run: npm install @actions/core @actions/github octokit/request-action@v1

- name: List issues
id: list-issues
run: |
const core = require('@actions/core');
const github = require('@actions/github');
const octokit = new github.GitHub(core.getInput('github-token'));
const owner = github.context.repo.owner;
const repo = github.context.repo.repo;
const issues = octokit.issues.listForRepo({
owner,
repo,
state: 'open', // You can adjust this to 'closed' or 'all' as needed
});
core.setOutput('issues', JSON.stringify(issues.data));
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Create branches
run: |
const core = require('@actions/core');
const github = require('@actions/github');
const octokit = new github.GitHub(core.getInput('github-token'));
const issues = JSON.parse(core.getInput('issues'));
for (const issue of issues) {
// Generate a branch name based on the issue number or title
const branchName = `issue-${issue.number}-${issue.title.replace(/\s+/g, '-').toLowerCase()}`;
// Create a new branch
octokit.git.createRef({
owner: github.context.repo.owner,
repo: github.context.repo.repo,
ref: `refs/heads/${branchName}`,
sha: github.context.sha, // Use the default branch's SHA here
});
}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 comments on commit 3977b9c

Please sign in to comment.