terraform-provider-file/.github/workflows/main-issue.yml

70 lines
3.0 KiB
YAML

name: MainIssue
# This workflow generates a "main" issue when a PR is created targeting main.
on:
pull_request_target:
branches: [main]
types: [opened]
jobs:
generate-issue:
name: 'Create Main Issue'
runs-on: ubuntu-latest
permissions:
issues: write
steps:
- uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0 https://github.com/actions/github-script
with:
script: |
const repo = context.repo.repo;
const owner = context.repo.owner;
const pr = context.payload.pull_request;
const newLabels = ['internal/main'];
const releaseLabel = pr.labels.find(label => label.name.startsWith('release/v'));
if (releaseLabel) {
newLabels.push(releaseLabel);
}
const assignees = ['matttrach', 'jiaqiluo', 'HarrisonWAffel'];
// Note: can't get terraform-maintainers team, the default token can't access org level objects
// Create the main issue
// https://docs.github.com/en/rest/issues/issues?apiVersion=2022-11-28#create-an-issue
// Note: issues can't have teams assigned to them
const newIssue = await github.rest.issues.create({
owner: owner,
repo: repo,
title: pr.title,
body: "This is the main issue tracking #" + pr.number + " \n\n" +
"Please add labels indicating the release versions eg. 'release/v0' \n\n" +
"Please add comments for user issues which this issue addresses. \n\n" +
"Description copied from PR: \n" + pr.body,
labels: newLabels,
assignees: assignees
});
if (releaseLabel) {
// if release label detected, then add appropriate sub-issues
const parentIssue = newIssue.data;
const parentIssueTitle = parentIssue.title;
const parentIssueNumber = parentIssue.number;
// Note: can't get terraform-maintainers team, the default token can't access org level objects
// Create the sub-issue
const newSubIssue = await github.rest.issues.create({
owner: owner,
repo: repo,
title: `Backport #${pr.number} to ${releaseLabel.name}`,
body: `Backport #${pr.number} to ${releaseLabel.name} for #${parentIssueNumber}`,
labels: [releaseLabel],
assignees: assignees
});
const subIssueId = newSubIssue.data.id;
// Attach the sub-issue to the parent using API request
await github.request('POST /repos/{owner}/{repo}/issues/{issue_number}/sub_issues', {
owner: owner,
repo: repo,
issue_number: parentIssueNumber,
sub_issue_id: subIssueId,
headers: {
'X-GitHub-Api-Version': '2022-11-28'
}
});
}