-
Notifications
You must be signed in to change notification settings - Fork 379
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
base: main
Are you sure you want to change the base?
Conversation
10ce875
to
61026e1
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
❗ 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. |
61026e1
to
b488fe0
Compare
src/github/issue-template.ts
Outdated
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}`); | ||
} | ||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
src/github/issue-template.ts
Outdated
constructor(github: GitHub, options: IssueTemplateOptions) { | ||
super(github.project); | ||
const project = github.project; |
There was a problem hiding this comment.
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:
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 | |
} |
There was a problem hiding this comment.
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.
test/github/issue-template.test.ts
Outdated
const project = new TestProject(); | ||
new IssueTemplate(project.github!, { | ||
templates: { | ||
"feature-request.yml": "<!-- Feature request template content -->", |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
8d5c534
to
1686653
Compare
* | ||
* @throws {Error} If an unsupported file extension is encountered. | ||
*/ | ||
public addTemplates(options: IssueTemplateOptions) { |
There was a problem hiding this comment.
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.
src/github/issue-template.ts
Outdated
const blankIssues = options.configOptions?.blankIssuesEnabled; | ||
const contactLinks = options.configOptions?.contactLinks; | ||
|
||
new YamlFile(project, ".github/config.yml", { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
new YamlFile(project, ".github/config.yml", { | |
new YamlFile(this, ".github/config.yml", { |
src/github/issue-template.ts
Outdated
const fileExtension = path.extname(fileName).toLowerCase(); | ||
switch (fileExtension) { | ||
case ".md": | ||
new TextFile(this.project, filePath, { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
new TextFile(this.project, filePath, { | |
new TextFile(this, filePath, { |
src/github/issue-template.ts
Outdated
}); | ||
break; | ||
case ".yml": | ||
new YamlFile(this.project, filePath, { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
new YamlFile(this.project, filePath, { | |
new YamlFile(this, filePath, { |
|
||
new IssueTemplate(project, { | ||
templates: { | ||
"feature-request.yml": YAML.stringify(data), |
There was a problem hiding this comment.
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);
There was a problem hiding this 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
61162b3
to
912ab2a
Compare
adds support for github issue templates. Closes #3567. Tested this by setting up a local project and adding this snippet to the
.projenrc.ts
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.