Skip to content

Commit

Permalink
fix(alert): handle splitted contribution (#276)
Browse files Browse the repository at this point in the history
  • Loading branch information
lionelB committed Jan 21, 2021
1 parent 95bcff3 commit 35512bb
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
13 changes: 12 additions & 1 deletion shared/types/index.d.ts
Expand Up @@ -44,17 +44,28 @@ export type ParseDilaReference = {
dila_container_id: string
}

export type Contribution = Omit<QuestionRaw, "title" | "answers"> & {
export type Contribution = Omit<QuestionRaw, "title" | "answers"> & Answers

type CCMultipleAnswers = {
answers: {
generic: GenericAnswer
conventions: Answer[]
}
}

type CCSingleAnswer = {
answers: {
generic: GenericAnswer
conventionAnswer: Answer
}
}

type GenericAnswer = Omit<GenericAnswerRaw, "references"> & {
references: ParseDilaReference[]
}

type Answer = Omit<AnswerRaw, "references"> & {
references: ParseDilaReference[]
}

type Answers = CCSingleAnswer | CCMultipleAnswers
21 changes: 20 additions & 1 deletion targets/alert-cli/src/extractDilaReferences/contribution.js
Expand Up @@ -21,7 +21,17 @@ export function extractContributionsRef(questions) {
},
references: question.document.answers.generic.references,
});

if (
!Object.prototype.hasOwnProperty.call(
question.document.answers,
"conventions"
)
) {
continue;
}
if (!isMultiConventionAnswer(question.document)) {
continue;
}
question.document.answers.conventions.forEach((answer) =>
references.push({
document: {
Expand All @@ -36,6 +46,15 @@ export function extractContributionsRef(questions) {
return references;
}

/**
* This is only to fool TS compiler
* @param {import("@shared/types").CCMultipleAnswers | import("@shared/types").CCSingleAnswer} a
* @returns {a is import("@shared/types").CCMultipleAnswers}
*/
function isMultiConventionAnswer(a) {
return "conventions" in a.answers;
}

export default async function main() {
if (!references) {
/** @type {import("@shared/types").ContributionDocument[]} */
Expand Down
2 changes: 1 addition & 1 deletion targets/alert-cli/src/index.js
Expand Up @@ -392,6 +392,6 @@ async function main() {
}

main().catch((error) => {
process.exit(1);
console.error(error);
process.exit(1);
});

0 comments on commit 35512bb

Please sign in to comment.