mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-03-23 07:02:38 +00:00
fix: build
This commit is contained in:
@@ -12,13 +12,11 @@
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {asyncPool} from '@krlwlfrt/async-pool';
|
||||
import {Api} from '@openstapps/gitlab-api';
|
||||
import {IssueState, Scope} from '@openstapps/gitlab-api/lib/types';
|
||||
import {Logger} from '@openstapps/logger';
|
||||
import moment from 'moment';
|
||||
import {flatten2dArray} from '../common';
|
||||
import {CONCURRENCY, GROUPS, LAST_MEETING, NOTE_PREFIX} from '../configuration';
|
||||
import {GROUPS, LAST_MEETING, NOTE_PREFIX} from '../configuration';
|
||||
import isBefore from 'date-fns/isBefore';
|
||||
|
||||
/**
|
||||
* Remove label `meeting` from closed issues
|
||||
@@ -26,34 +24,38 @@ import {CONCURRENCY, GROUPS, LAST_MEETING, NOTE_PREFIX} from '../configuration';
|
||||
* @param api Instance of GitLabAPI to send requests with
|
||||
*/
|
||||
export async function unlabel(api: Api) {
|
||||
const issueResults = await asyncPool(CONCURRENCY, GROUPS, async groupId => {
|
||||
return api.getIssues({
|
||||
groupId: groupId,
|
||||
state: IssueState.CLOSED,
|
||||
});
|
||||
});
|
||||
|
||||
const issues = flatten2dArray(issueResults);
|
||||
const issues = await Promise.all(
|
||||
GROUPS.map(async groupId => {
|
||||
return api.getIssues({
|
||||
groupId: groupId,
|
||||
state: IssueState.CLOSED,
|
||||
});
|
||||
}),
|
||||
).then(it => it.flat());
|
||||
|
||||
Logger.log(`Fetched ${issues.length} closed issue(s).`);
|
||||
|
||||
await asyncPool(CONCURRENCY, issues, async issue => {
|
||||
if (
|
||||
issue.labels.includes('meeting') &&
|
||||
issue.closed_at !== null &&
|
||||
moment(issue.closed_at).isBefore(LAST_MEETING)
|
||||
) {
|
||||
Logger.info(`Issue ${issue.title} is closed before last meeting and has label "meeting". Removing it.`);
|
||||
await Promise.all(
|
||||
issues.map(async issue => {
|
||||
if (
|
||||
issue.labels.includes('meeting') &&
|
||||
issue.closed_at !== null &&
|
||||
isBefore(new Date(issue.closed_at), LAST_MEETING)
|
||||
) {
|
||||
Logger.info(
|
||||
`Issue ${issue.title} is closed before last meeting and has label "meeting". Removing it.`,
|
||||
);
|
||||
|
||||
await api.createNote(
|
||||
issue.project_id,
|
||||
Scope.ISSUES,
|
||||
issue.iid,
|
||||
`${NOTE_PREFIX} Removed label \`meeting\` automatically.
|
||||
await api.createNote(
|
||||
issue.project_id,
|
||||
Scope.ISSUES,
|
||||
issue.iid,
|
||||
`${NOTE_PREFIX} Removed label \`meeting\` automatically.
|
||||
/unlabel ~meeting`,
|
||||
);
|
||||
}
|
||||
});
|
||||
);
|
||||
}
|
||||
}),
|
||||
);
|
||||
|
||||
Logger.ok('Label `meeting` has been removed from closed issues.');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user