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

feat(github): add support for github issue templates #3648

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

kennyg
Copy link
Contributor

@kennyg kennyg commented Jun 9, 2024

adds support for github issue templates. Closes #3567. Tested this by setting up a local project and adding this snippet to the .projenrc.ts

new IssueTemplate(project.github!, {
  templates: {
    'bug-report.md': '<!-- Bug report template content -->',
    'feature-request.yml': '<!-- Feature request template content -->',
  },
});

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@kennyg kennyg marked this pull request as draft June 9, 2024 15:23
@kennyg kennyg force-pushed the gh-issue-templates branch from 10ce875 to 61026e1 Compare June 9, 2024 16:25
@codecov-commenter
Copy link

codecov-commenter commented Jun 9, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.38%. Comparing base (ad20d2c) to head (912ab2a).
Report is 112 commits behind head on main.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3648      +/-   ##
==========================================
+ Coverage   96.34%   96.38%   +0.03%     
==========================================
  Files         192      195       +3     
  Lines       37696    38200     +504     
  Branches     3524     3571      +47     
==========================================
+ Hits        36320    36819     +499     
- Misses       1376     1381       +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@kennyg kennyg force-pushed the gh-issue-templates branch from 61026e1 to b488fe0 Compare June 9, 2024 16:35
@kennyg kennyg marked this pull request as ready for review June 9, 2024 16:36
@mrgrain mrgrain changed the title feat: add support for github issue templates feat(github): add support for github issue templates Jun 10, 2024
Comment on lines 86 to 121
for (const [fileName, content] of Object.entries(options.templates)) {
const filePath = path.join(templatePath, fileName);
const fileExtension = path.extname(fileName).toLowerCase();
switch (fileExtension) {
case ".md":
new TextFile(project, filePath, {
lines: [content],
marker: false,
committed: true,
});
break;
case ".yml":
new YamlFile(project, filePath, {
obj: content,
marker: false,
committed: true,
});
break;
default:
throw new Error(`Unsupported file extension: ${fileExtension}`);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's convert this into a public addTemplate() class method so it can be reused.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sounds good. i've made the change.

Comment on lines 79 to 81
constructor(github: GitHub, options: IssueTemplateOptions) {
super(github.project);
const project = github.project;
Copy link
Contributor

Choose a reason for hiding this comment

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

We have moved on from this approach. This is the current state of the art:

Suggested change
constructor(github: GitHub, options: IssueTemplateOptions) {
super(github.project);
const project = github.project;
constructor(scope: IScope, options: IssueTemplateOptions) {
super(scope, "<enter_unique_id_here_if_this_is_a_singleton_component>");
const project = this.project;
const github = GitHub.of(project);
if (!github) {
// add warning here. Or hard fail, but it seems like the github component is not actually needed for this
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

also updated this. thanks for the tip.

const project = new TestProject();
new IssueTemplate(project.github!, {
templates: {
"feature-request.yml": "<!-- Feature request template content -->",
Copy link
Contributor

Choose a reason for hiding this comment

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

doesn't a yaml file imply using an object here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

you're right. I updated the tests to reflect that.

@kennyg kennyg force-pushed the gh-issue-templates branch 2 times, most recently from 8d5c534 to 1686653 Compare June 15, 2024 17:22
*
* @throws {Error} If an unsupported file extension is encountered.
*/
public addTemplates(options: IssueTemplateOptions) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Neither options.configOptions nor options.templatePath are used. This should take the templates directly.

const blankIssues = options.configOptions?.blankIssuesEnabled;
const contactLinks = options.configOptions?.contactLinks;

new YamlFile(project, ".github/config.yml", {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
new YamlFile(project, ".github/config.yml", {
new YamlFile(this, ".github/config.yml", {

const fileExtension = path.extname(fileName).toLowerCase();
switch (fileExtension) {
case ".md":
new TextFile(this.project, filePath, {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
new TextFile(this.project, filePath, {
new TextFile(this, filePath, {

});
break;
case ".yml":
new YamlFile(this.project, filePath, {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
new YamlFile(this.project, filePath, {
new YamlFile(this, filePath, {


new IssueTemplate(project, {
templates: {
"feature-request.yml": YAML.stringify(data),
Copy link
Contributor

Choose a reason for hiding this comment

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

I was more hoping to create an API that can take in objects directly. Having to stringify data just for it to be parsed again seems counter-intuitive.

I'd suggest an enum-like class approach:

IssueTemplate.markdown(markdown: string);
IssueTemplate.form(data: IssueFormSchema);

Copy link
Contributor

@mrgrain mrgrain left a comment

Choose a reason for hiding this comment

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

Just need to do something about the API for forms

@kennyg kennyg marked this pull request as draft June 18, 2024 21:39
@kennyg kennyg force-pushed the gh-issue-templates branch from 61162b3 to 912ab2a Compare June 22, 2024 12:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

github issue template
3 participants