2023-09-22 04:35:24 -04:00
|
|
|
const { recordRuleExitStatus } = require("./configParameters.js");
|
|
|
|
|
2023-03-20 09:01:14 -04:00
|
|
|
/**
|
|
|
|
* Check if MR has area labels (light blue labels)
|
|
|
|
*
|
|
|
|
* @dangerjs WARN
|
|
|
|
*/
|
|
|
|
module.exports = async function () {
|
2023-09-22 04:35:24 -04:00
|
|
|
const ruleName = "Merge request area labels";
|
2023-03-20 09:01:14 -04:00
|
|
|
const projectId = 103; // ESP-IDF
|
2023-03-30 05:23:41 -04:00
|
|
|
const areaLabelColor = /^#d2ebfa$/i; // match color code (case-insensitive)
|
2023-03-20 09:01:14 -04:00
|
|
|
const projectLabels = await danger.gitlab.api.Labels.all(projectId); // Get all project labels
|
|
|
|
const areaLabels = projectLabels
|
2023-03-30 05:23:41 -04:00
|
|
|
.filter((label) => areaLabelColor.test(label.color))
|
2023-03-20 09:01:14 -04:00
|
|
|
.map((label) => label.name); // Filter only area labels
|
|
|
|
const mrLabels = danger.gitlab.mr.labels; // Get MR labels
|
|
|
|
|
|
|
|
if (!mrLabels.some((label) => areaLabels.includes(label))) {
|
2023-09-22 04:35:24 -04:00
|
|
|
recordRuleExitStatus(ruleName, "Failed");
|
|
|
|
return warn(
|
2023-03-20 09:01:14 -04:00
|
|
|
`Please add some [area labels](${process.env.DANGER_GITLAB_HOST}/espressif/esp-idf/-/labels) to this MR.`
|
|
|
|
);
|
|
|
|
}
|
2023-09-22 04:35:24 -04:00
|
|
|
|
|
|
|
// At this point, the rule has passed
|
|
|
|
recordRuleExitStatus(ruleName, "Passed");
|
2023-03-20 09:01:14 -04:00
|
|
|
};
|