Skip to content

Instantly share code, notes, and snippets.

@beshur
Created September 1, 2022 10:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save beshur/72e626649b735824b9e1fedd9fd0f627 to your computer and use it in GitHub Desktop.
Save beshur/72e626649b735824b9e1fedd9fd0f627 to your computer and use it in GitHub Desktop.
Danger.js create gitlab thread
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,
);
}
});
}
}
@beshur
Copy link
Author

beshur commented Sep 1, 2022

This one checks if there are changes in lang/en.json file, and if at the same time there are no changes in lang/de.json (which would be the sign that the translations are needed, then it creates the thread to notify the developer of it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment