in functions/src/issues.ts [191:261]
async onNewIssue(
repo: types.internal.Repository,
issue: types.internal.Issue
): Promise<types.Action[]> {
const actions: types.Action[] = [];
const org = repo.owner.login;
const name = repo.name;
// When an issue is transferred from one repo to another GitHub uses the new-issue
// event but we shouldn't process it like that, a human has already looked at it.
if (issue.changes && issue.changes.old_issue) {
log.debug(
`onNewIssue: ignoring issue transferred from ${issue.changes.old_issue.url}`
);
return actions;
}
const repoFeatures = this.config.getRepoFeatures(org, name);
log.debug(
`onNewIssue: ${name} has features ${JSON.stringify(repoFeatures)}`
);
// Basic issue categorization, which involves adding labels
// based on matching configuration.
const categorization = this.categorizeNewIssue(repo, issue);
if (repoFeatures.issue_labels) {
actions.push(...categorization.actions);
}
// If the issue is filed by a collaborator, we stop here.
const isCollaborator = await snapshot.userIsCollaborator(
org,
name,
issue.user.login
);
if (isCollaborator) {
actions.push(
new types.GitHubNoOpAction(
org,
name,
issue.number,
`No further action taken on this issue because it was filed by repo collaborator: ${issue.user.login}`
)
);
return actions;
}
// If the issue needs triage, there's a fixed label and comment
if (repoFeatures.issue_labels && categorization.needs_triage) {
actions.push(...this.markNeedsTriage(repo, issue));
}
// Check if it matches the template. This feature is implicitly enabled by
// the template having "matchable" structure so there is no need to check
// the repo's configuration.
const templateActions = await this.checkNewIssueTemplate(repo, issue);
// There are some situations where we don't want to nag about the template
// 1) This is a feature request
// 2) We were able to label with some something besides needs_triage
const shouldValidateTemplate = !(
categorization.is_fr || categorization.matched_label
);
if (shouldValidateTemplate) {
actions.push(...templateActions);
}
// Return a list of actions to do
return actions;
}