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

Add script to add PR & Issue templates to all IaC repos #58

Merged
merged 5 commits into from
Nov 4, 2021
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
161 changes: 161 additions & 0 deletions scripts/add-or-update-pr-issue-templates.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
#!/usr/bin/env bash

# This script will ensure a repo has the necessary pull request and issue templates as
# part of our contributing guide: https://doc.gruntwork.io/guides/contributing/
#
# It creates or replaces the following files:
# .github/ISSUE_TEMPLATE/bug_report.md
# .github/ISSUE_TEMPLATE/feature_request.md
# .github/pull_request_template.md

function create_bug_issue_template {
cat << "EOF" > .github/ISSUE_TEMPLATE/bug_report.md
---
name: Bug report
about: Create a bug report to help us improve.
title: ''
labels: bug
assignees: ''

---

<!--
Have any questions? Check out the contributing docs at https://gruntwork.notion.site/Gruntwork-Coding-Methodology-02fdcd6e4b004e818553684760bf691e, or
ask in this issue and a Gruntwork core maintainer will be happy to help :)
-->

**Describe the bug**
A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the behavior including the relevant Terraform/Terragrunt/Packer version number and any code snippets and module inputs you used.

```hcl
// paste code snippets here
```

**Expected behavior**
A clear and concise description of what you expected to happen.

**Nice to have**
- [ ] Terminal output
- [ ] Screenshots

**Additional context**
Add any other context about the problem here.
EOF
}

function create_feature_issue_template {
cat << "EOF" > .github/ISSUE_TEMPLATE/feature_request.md
---
name: Feature request
about: Submit a feature request for this repo.
title: ''
labels: enhancement
assignees: ''

---

<!--
Have any questions? Check out the contributing docs at https://gruntwork.notion.site/Gruntwork-Coding-Methodology-02fdcd6e4b004e818553684760bf691e, or
ask in this issue and a Gruntwork core maintainer will be happy to help :)
-->

**Describe the solution you'd like**
A clear and concise description of what you want to happen.

**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.

**Additional context**
Add any other context or screenshots about the feature request here.
EOF
}

function create_pr_template {
cat << "EOF" > .github/pull_request_template.md
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: should these be .md files checked into this git-xargs repo? You could then use cp to copy them to the proper destination. It would then make it easier to read / edit / preview those files than when they are inlined within a Bash script.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@brikis98 we can, but it would be the first script example that copies external files to a repo. I guess this is not such a bad thing, but it will also make the script slightly less portable. I.e. The user would need to ensure they copy a folder containing the script and all of the required templates for it to work 100% correctly. We could fail hard if one of the templates is missing. @zackproser what are your thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moving the markdown files to the git-xargs repo would make them slightly easier to read, but we'd also have the extra step of ensuring we've updated and pulled on the repo each time for running the latest script, as Rob points out. I don't have a strong opinion here, so I'd say go with whatever is easier for you.

Makes me think git-xargs might do well with a means of fingerprinting the script or command it ran each time and adding that info to a PR description or something - for easier coordination in the common workflow of needing to make several small updates to a script following the first couple of runs. This would make it easier for colleagues to know which version of a script generated which PRs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes me think git-xargs might do well with a means of fingerprinting the script or command it ran each time and adding that info to a PR description or something - for easier coordination in the common workflow of needing to make several small updates to a script following the first couple of runs. This would make it easier for colleagues to know which version of a script generated which PRs.

Yeah, that's a good idea. We've been in a very similar territory recently planning an internal project. It appears RenovateBot actually stores a fair bit of state using pull requests. i.e: It knows whether a repo has been onboarded or not based on the status of a PR. I think it would be handy if git-xargs could by default sprinkle some metadata into the PRs.

<!--
Have any questions? Check out the contributing docs at https://gruntwork.notion.site/Gruntwork-Coding-Methodology-02fdcd6e4b004e818553684760bf691e, or
ask in this Pull Request and a Gruntwork core maintainer will be happy to help :)
Note: Remember to add '[WIP]' to the beginning of the title if this PR is still a work-in-progress.
-->

## Description

<!-- Write a brief description of the changes introduced by this PR -->

### Documentation

<!--
If this is a feature PR, then where is it documented?

- If docs exist:
- Update any references, if relevant.
- If no docs exist:
- Create a stub for documentation including bullet points for how to use the feature, code snippets (including from happy path tests), etc.
-->

<!-- Important: Did you make any backwards incompatible changes? If yes, then you must write a migration guide! -->

## TODOs

- [ ] Ensure the branch is named correctly with the issue number. e.g: `feature/new-vpc-endpoints-955` or `bug/missing-count-param-434`.
- [ ] Update the docs.
- [ ] Keep the changes backwards compatible where possible.
- [ ] Run the pre-commit checks successfully.
- [ ] Run the relevant tests successfully.
- [ ] Ensure any 3rd party code adheres with our license policy: https://www.notion.so/gruntwork/Gruntwork-licenses-and-open-source-usage-policy-f7dece1f780341c7b69c1763f22b1378
- [ ] _Maintainers Only._ If necessary, release a new version of this repo.
- [ ] _Maintainers Only._ If there were backwards incompatible changes, include a migration guide in the release notes.
- [ ] _Maintainers Only._ Add to the next version of the monthly newsletter (see https://www.notion.so/gruntwork/Monthly-Newsletter-9198cbe7f8914d4abce23dca7b435f43).


## Related Issues

<!--
Link to the issue that is fixed by this PR (if there is one)
e.g. Fixes #1234

Link to an issue that is partially addressed by this PR (if there are any)
e.g. Addresses #1234

Link to related issues (if there are any)
e.g. Related to #1234
-->
EOF
}

# Ensure the GitHub template directories exist
mkdir -p .github
mkdir -p .github/ISSUE_TEMPLATE

# if the repo does not contain a bug_report.md file, then create one or replace the existing one
if [[ ! -f ".github/ISSUE_TEMPLATE/bug_report.md" ]]; then
echo "Could not find file at .github/ISSUE_TEMPLATE/bug_report.md, so adding one..."
create_bug_issue_template
else
echo "Found file at .github/ISSUE_TEMPLATE/bug_report.md, so replacing it..."
rm .github/ISSUE_TEMPLATE/bug_report.md
create_bug_issue_template
fi

# if the repo does not contain a feature_request.md file, then create one or replace the existing one
if [[ ! -f ".github/ISSUE_TEMPLATE/feature_request.md" ]]; then
echo "Could not find file at .github/ISSUE_TEMPLATE/feature_request.md, so adding one..."
create_feature_issue_template
else
echo "Found file at .github/ISSUE_TEMPLATE/feature_request.md, so replacing it..."
rm .github/ISSUE_TEMPLATE/feature_request.md
create_feature_issue_template
fi

# if the repo does not contain a pull_request_template.md file, then create one or replace the existing one
if [[ ! -f ".github/pull_request_template.md" ]]; then
echo "Could not find file at .github/pull_request_template.md, so adding one..."
create_pr_template
else
echo "Found file at .github/pull_request_template.md, so replacing it..."
rm .github/pull_request_template.md
create_pr_template
fi