Plugins
Extend GitWire's expression language with custom JavaScript filter functions. Place .js files in .gitwire/plugins/ in your repository.
How It Works
- GitWire fetches all
.jsfiles from.gitwire/plugins/in your repo - Each file is loaded in a sandboxed context (no
require,fs,process,fetch) - Exported functions become filter functions available in expressions
- Plugins are cached alongside config (5-minute TTL)
Example Plugin
File: .gitwire/plugins/team-filters.js
javascript
// Custom filter: check if author belongs to a team
module.exports.inTeam = function(author, teamName) {
var teams = {
frontend: ["alice", "bob", "charlie"],
backend: ["dave", "eve", "frank"],
security: ["grace", "heidi"],
};
return (teams[teamName] || []).indexOf(author) !== -1;
};
// Custom filter: check if any file is a package manifest
module.exports.touchesPackage = function(files) {
return files.some(function(f) {
return f === "package.json" || f === "requirements.txt";
});
};Usage in rules:
yaml
custom_rules:
frontend_review:
if: "author | inTeam('frontend')"
run:
- action: add-label
args: { label: "frontend" }
package_change_alert:
if: "files | touchesPackage()"
run:
- action: add-label
args: { label: "package-change" }Sandbox Restrictions
Plugins run in a restricted JavaScript context. The following are not available:
require()— no module loadingprocess— no environment accessfs— no filesystem accessfetch,XMLHttpRequest— no network requestssetTimeout,setInterval— no timersBuffer,URL— no Node.js built-ins
Available globals: JSON, Math, Array, Object, String, Number, Boolean, Date, RegExp, Map, Set, parseInt, parseFloat, console (silenced).
Rules
- Export functions only — objects, strings, and numbers are ignored
- Functions must be pure — no side effects, no external calls
- Functions must be synchronous — no async/await or Promises
- Functions must complete quickly — complex computation should be avoided
- Use
module.exports— ESMexportsyntax is not supported in plugins
File Structure
your-repo/
├── .gitwire/
│ ├── .gitwire.yml # Config file
│ └── plugins/
│ ├── team-filters.js # Team-based filters
│ └── size-filters.js # Size-based filters
└── ...Error Handling
- If a plugin file has a syntax error, it's skipped (other plugins still load)
- If a plugin function throws at runtime, the rule that used it is skipped
- Plugin errors are logged but don't block the worker pipeline
Security Model
Plugins are intentionally limited. If you need complex logic (API calls, database queries), implement it as a worker in the GitWire backend, not as a plugin.
See: Custom Rules | Expression Language