How Gitar’s Feature Flag Cleanup Works
Gitar’s feature flag cleanup product removes stale feature flags from a repo by rewriting code to replace calls to a feature flag library with the flag’s final value. Gitar performs feature flag cleanup using traditional compiler and code analysis techniques. It parses the source code into an internal representation, analyzes this representation to find stale feature flag references, replaces them with the final value of the flag, and finally cleans up the code using compiler optimization techniques to delete code that becomes unnecessary as a result of removing the feature flag. The core rewrite engine is forked from the open source Piranha project.
The details on how this technology works is published in this ACM paper and in these blog posts:
- Designing a Lightweight Polyglot Code Transformation Language,
- Automated Refactoring at Scale,
- Introducting Piranha: An Open Source Tool to Automatically Delete Stale Code
Gitar runs as a managed cloud service (currently running in AWS) that accesses git repos and creates PRs via GitHub.
Gitar service
The Gitar service is installed as a GitHub app from the GitHub marketplace. This app allows a user to trigger a flag cleanup by adding a @gitar-bot comment on any GitHub issue or PR. The Gitar cloud service receives webhook events from the GitHub app that invoke its feature flag cleanup.
The Gitar service
- checks out a copy of a repo,
- applies its transformations to cleanup a feature flag,
- posts a PR back to GitHub or GitLab, and then
- deletes the checked out copy of the git repo.
Gitar does not retain any of the checked code after posting the PR.