mirror of
https://github.com/wekan/wekan.git
synced 2026-11-20 09:45:04 -05:00
Import -> GitHub -> Import a whole GitHub organization makes every repository of an organization or user its own board, opening in Board View / Version Control. Issues go through the ordinary importBoard, as the person who started the job, with their comments, labels and files. Releases are cards in a Releases list, their files attached only when chosen. Each .github/workflows file becomes Rules. The wiki is read from its git repository with isomorphic-git (1.42.4, pinned), every request through the SSRF guard and only to github.com: a page is a card in the Wiki list, its [[links]] point at and are attached to the linked pages' cards, and each commit that changed it is a dated edit in the card's history, so Restore brings back an older version. The job shows progress, can be cancelled, pauses on a restart and stops at a rate limit; the token is kept in memory only. Version Control gains Releases and Wiki tabs: the wiki as GitHub shows it, with the page list, _Sidebar and _Footer, links that stay in the tab, and each page's history with Restore. GitHub Actions workflows map to Rules: issue events to triggers, label, close, reopen, comment, assign and create steps to actions, actions/stale to an aging rule. Code - builds, tests, scripts - is never run: such a workflow is a disabled rule with its YAML as the description. WeKan's Rules gain what they lacked for it: a "commented on" trigger, an "add comment" action written as the person whose change ran the rule and only where they may comment, cron schedules in UTC, and a rule description shown on the rule. A disabled rule no longer fires on a schedule or from its button, which it did. The new strings are translated in every locale. Thanks to xet7 !
166 lines
5.1 KiB
JavaScript
166 lines
5.1 KiB
JavaScript
import { ReactiveCache } from '/imports/reactiveCache';
|
|
import { Mongo } from 'meteor/mongo';
|
|
import { Meteor } from 'meteor/meteor';
|
|
import Triggers from './triggers';
|
|
import Actions from './actions';
|
|
import { generateDefaultRuleTitle } from './lib/generateDefaultRuleTitle';
|
|
const { SimpleSchema } = require('/imports/simpleSchema');
|
|
|
|
const Rules = new Mongo.Collection('rules');
|
|
|
|
Rules.attachSchema(
|
|
new SimpleSchema({
|
|
title: {
|
|
type: String,
|
|
optional: false,
|
|
// #4294: a rule created with no title used to store an empty string
|
|
// (the client-side "Add Rule" gate is the primary defence against
|
|
// that, but every creation path goes through this schema, including
|
|
// the rules.createRule server method and the rules-workflow canvas).
|
|
// Once trigger+action are known, generate a sensible default instead
|
|
// of leaving the rule unnamed; an existing/explicit title always wins.
|
|
// eslint-disable-next-line consistent-return
|
|
autoValue() {
|
|
const value = this.value;
|
|
if (value !== undefined && value !== null && `${value}`.trim() !== '') {
|
|
return value;
|
|
}
|
|
if (this.isInsert) {
|
|
const triggerId = this.field('triggerId').value;
|
|
const actionId = this.field('actionId').value;
|
|
try {
|
|
const trigger = triggerId && Triggers.findOne(triggerId);
|
|
const action = actionId && Actions.findOne(actionId);
|
|
return generateDefaultRuleTitle(
|
|
trigger && trigger.desc,
|
|
action && action.desc,
|
|
);
|
|
} catch (e) {
|
|
return 'Rule';
|
|
}
|
|
}
|
|
// An update that sent no title (e.g. a partial $set from elsewhere)
|
|
// must not blank out an existing one.
|
|
this.unset();
|
|
},
|
|
},
|
|
triggerId: {
|
|
type: String,
|
|
optional: false,
|
|
},
|
|
actionId: {
|
|
type: String,
|
|
optional: false,
|
|
},
|
|
// #4294 / #2953: further triggers (the rule fires when ANY fires) and
|
|
// further actions (run in order after actionId). See models/lib/ruleParts.js.
|
|
extraTriggerIds: {
|
|
type: Array,
|
|
optional: true,
|
|
maxCount: 10,
|
|
},
|
|
'extraTriggerIds.$': { type: String },
|
|
extraActionIds: {
|
|
type: Array,
|
|
optional: true,
|
|
maxCount: 10,
|
|
},
|
|
'extraActionIds.$': { type: String },
|
|
boardId: {
|
|
type: String,
|
|
optional: false,
|
|
},
|
|
// Denormalised manual-button metadata (only present on button rules). The
|
|
// board view renders board/card buttons from the rule alone — see
|
|
// server/rulesButton.js (rules.createRule) for why the trigger document is
|
|
// not relied upon on the client.
|
|
buttonType: {
|
|
type: String,
|
|
optional: true,
|
|
allowedValues: ['card', 'board'],
|
|
},
|
|
buttonLabel: {
|
|
type: String,
|
|
optional: true,
|
|
},
|
|
// #2322: temporarily disable a rule without deleting it. Defaults to
|
|
// `true` so every rule that existed before this field was added (and any
|
|
// rule created without explicitly setting it) keeps firing exactly as
|
|
// before - only an explicit flip to `false` (rules.setEnabled) stops a
|
|
// rule's trigger/action from being evaluated; its Trigger/Action
|
|
// documents and the rule's own configuration are untouched either way.
|
|
description: {
|
|
/**
|
|
* What the rule is for, in Markdown. An imported GitHub Actions
|
|
* workflow keeps its YAML here (models/lib/githubActionsRules.js).
|
|
*/
|
|
type: String,
|
|
optional: true,
|
|
max: 200000,
|
|
},
|
|
enabled: {
|
|
type: Boolean,
|
|
optional: true,
|
|
defaultValue: true,
|
|
},
|
|
createdAt: {
|
|
type: Date,
|
|
optional: true,
|
|
// eslint-disable-next-line consistent-return
|
|
autoValue() {
|
|
if (this.isInsert) {
|
|
return new Date();
|
|
} else if (this.isUpsert) {
|
|
return { $setOnInsert: new Date() };
|
|
} else {
|
|
this.unset();
|
|
}
|
|
},
|
|
},
|
|
modifiedAt: {
|
|
type: Date,
|
|
// eslint-disable-next-line consistent-return
|
|
autoValue() {
|
|
if (this.isInsert || this.isUpsert || this.isUpdate) {
|
|
return new Date();
|
|
} else {
|
|
this.unset();
|
|
}
|
|
},
|
|
},
|
|
}),
|
|
);
|
|
|
|
Rules.helpers({
|
|
async rename(description) {
|
|
return await Rules.updateAsync(this._id, { $set: { description } });
|
|
},
|
|
getAction() {
|
|
return ReactiveCache.getAction(this.actionId);
|
|
},
|
|
getTrigger() {
|
|
return ReactiveCache.getTrigger(this.triggerId);
|
|
},
|
|
board() {
|
|
return ReactiveCache.getBoard(this.boardId);
|
|
},
|
|
trigger() {
|
|
return ReactiveCache.getTrigger(this.triggerId);
|
|
},
|
|
action() {
|
|
return ReactiveCache.getAction(this.actionId);
|
|
},
|
|
});
|
|
|
|
if (Meteor.isServer) {
|
|
// Admin Panel / Problems / Rules pages every rule sorted by board, and counts
|
|
// them with the same selector (server/publications/rules.js). Without an index
|
|
// that is a full-collection scan plus an in-memory sort for every page of ten.
|
|
const { ensureIndex } = require('/server/lib/mongoStartup');
|
|
Meteor.startup(async () => {
|
|
await ensureIndex(Rules, { boardId: 1 });
|
|
});
|
|
}
|
|
|
|
export default Rules;
|