Created
September 1, 2022 10:24
-
-
Save beshur/72e626649b735824b9e1fedd9fd0f627 to your computer and use it in GitHub Desktop.
Danger.js create gitlab thread
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {danger} from 'danger'; | |
const enFile = 'lang/en.json'; | |
const deFile = 'lang/de.json'; | |
const NEEDS_TRANSLATION = | |
'🌍 This MR contains changes in translation files, do not forget to run translation script right before the merge.'; | |
if (danger.git.modified_files.includes(enFile)) { | |
if (!danger.git.modified_files.includes(deFile)) { | |
danger.gitlab.api.MergeRequestDiscussions.all( | |
danger.gitlab.metadata.repoSlug, | |
danger.gitlab.metadata.pullRequestID, | |
).then((res) => { | |
const translationNoteExists = res?.find((item) => item.notes.find((note) => note.body === NEEDS_TRANSLATION)); | |
console.log('danger: translationNoteExists', translationNoteExists); | |
if (!translationNoteExists) { | |
console.log('danger: creating translation note'); | |
danger.gitlab.api.MergeRequestDiscussions.create( | |
danger.gitlab.metadata.repoSlug, | |
danger.gitlab.metadata.pullRequestID, | |
NEEDS_TRANSLATION, | |
); | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This one checks if there are changes in
lang/en.json
file, and if at the same time there are no changes inlang/de.json
(which would be the sign that the translations are needed, then it creates the thread to notify the developer of it.