ai-cr 0.1.0__py3-none-any.whl → 0.4.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ai_code_review/.ai-code-review.toml +305 -0
- ai_code_review/__init__.py +0 -0
- ai_code_review/bootstrap.py +37 -0
- ai_code_review/cli.py +112 -0
- ai_code_review/constants.py +7 -0
- ai_code_review/core.py +114 -0
- ai_code_review/project_config.py +99 -0
- ai_code_review/report_struct.py +108 -0
- ai_code_review/utils.py +75 -0
- ai_cr-0.4.2.dist-info/METADATA +161 -0
- ai_cr-0.4.2.dist-info/RECORD +14 -0
- ai_cr-0.4.2.dist-info/entry_points.txt +3 -0
- .git/COMMIT_EDITMSG +0 -1
- .git/FETCH_HEAD +0 -1
- .git/HEAD +0 -1
- .git/ORIG_HEAD +0 -1
- .git/config +0 -57
- .git/description +0 -1
- .git/hooks/applypatch-msg.sample +0 -15
- .git/hooks/commit-msg.sample +0 -24
- .git/hooks/fsmonitor-watchman.sample +0 -174
- .git/hooks/post-update.sample +0 -8
- .git/hooks/pre-applypatch.sample +0 -14
- .git/hooks/pre-commit.sample +0 -49
- .git/hooks/pre-merge-commit.sample +0 -13
- .git/hooks/pre-push.sample +0 -53
- .git/hooks/pre-rebase.sample +0 -169
- .git/hooks/pre-receive.sample +0 -24
- .git/hooks/prepare-commit-msg.sample +0 -42
- .git/hooks/push-to-checkout.sample +0 -78
- .git/hooks/sendemail-validate.sample +0 -77
- .git/hooks/update.sample +0 -128
- .git/index +0 -0
- .git/info/exclude +0 -6
- .git/logs/HEAD +0 -56
- .git/logs/refs/heads/ISS14 +0 -3
- .git/logs/refs/heads/PR5 +0 -3
- .git/logs/refs/heads/distr +0 -3
- .git/logs/refs/heads/github_workflow +0 -11
- .git/logs/refs/heads/main +0 -6
- .git/logs/refs/heads/pr10 +0 -3
- .git/logs/refs/heads/pr11 +0 -1
- .git/logs/refs/heads/pr12 +0 -2
- .git/logs/refs/heads/pr13 +0 -3
- .git/logs/refs/heads/pr14 +0 -2
- .git/logs/refs/heads/pr15 +0 -2
- .git/logs/refs/heads/pr2 +0 -2
- .git/logs/refs/heads/pr3 +0 -2
- .git/logs/refs/heads/pr4 +0 -2
- .git/logs/refs/heads/pr6 +0 -3
- .git/logs/refs/heads/pr8 +0 -2
- .git/logs/refs/heads/pr9 +0 -3
- .git/logs/refs/remotes/origin/HEAD +0 -1
- .git/logs/refs/remotes/origin/ISS14 +0 -2
- .git/logs/refs/remotes/origin/PR5 +0 -2
- .git/logs/refs/remotes/origin/distr +0 -2
- .git/logs/refs/remotes/origin/github_workflow +0 -10
- .git/logs/refs/remotes/origin/main +0 -5
- .git/logs/refs/remotes/origin/pr10 +0 -2
- .git/logs/refs/remotes/origin/pr12 +0 -1
- .git/logs/refs/remotes/origin/pr13 +0 -2
- .git/logs/refs/remotes/origin/pr14 +0 -2
- .git/logs/refs/remotes/origin/pr15 +0 -1
- .git/logs/refs/remotes/origin/pr2 +0 -1
- .git/logs/refs/remotes/origin/pr3 +0 -1
- .git/logs/refs/remotes/origin/pr4 +0 -1
- .git/logs/refs/remotes/origin/pr6 +0 -2
- .git/logs/refs/remotes/origin/pr8 +0 -1
- .git/logs/refs/remotes/origin/pr9 +0 -2
- .git/objects/00/e15c53e2190ca590a9fbe6c9b292178568cef8 +0 -0
- .git/objects/01/53ccf25d39e1ede671aa7b8f923d9e41890237 +0 -0
- .git/objects/01/e234feef599ebafee61c7a0a8685db305d6ccc +0 -0
- .git/objects/03/50c4a3b1b2a53eb2407badf3190c9093aef7f7 +0 -0
- .git/objects/03/7585e81567a46b86bdb12cacb8fe7a6b26cc0d +0 -0
- .git/objects/07/10acf175ac4d747e6d387e2813700f078f32be +0 -0
- .git/objects/07/711175e105bcf158fd31e720d28cc69b7e34d5 +0 -0
- .git/objects/09/65927d61c531e119991f121c1a19d578c65b3d +0 -0
- .git/objects/0a/096ef88c1aa81728774dd1c7e8c79bcf5c491e +0 -6
- .git/objects/0a/f4884b0f660b9e10ad51aaaee68c563ee83a73 +0 -0
- .git/objects/0c/96607ea9c9b2e4678f94da89aedea2bcd94cda +0 -0
- .git/objects/0d/cc4204ea2df65333510becfbc85182f113d33e +0 -0
- .git/objects/10/427d29d8b95bbb09784f6241002fa117d3dd0f +0 -0
- .git/objects/10/5ce2da2d6447d11dfe32bfb846c3d5b199fc99 +0 -0
- .git/objects/13/566b81b018ad684f3a35fee301741b2734c8f4 +0 -2
- .git/objects/15/8c2f20a3f3423f7675f4816add1429a0223266 +0 -0
- .git/objects/17/fb2589bea7ec4f87bdb4c9a1481d09594656ac +0 -0
- .git/objects/1d/3278e0f366dcec4cd5e98a62ccf104f28f265d +0 -0
- .git/objects/1d/ceebc9439f6cba980508f103677a80f97a672a +0 -0
- .git/objects/1f/a58087175ca3cf46c3348482595c9783426471 +0 -0
- .git/objects/1f/b285986eb7755c6345085c6f3289c750adb2c1 +0 -0
- .git/objects/23/8df90734a6bdbe960bd970867a023f88664892 +0 -0
- .git/objects/24/af438231a0bedf68e2070aa46b2faab13c2af6 +0 -0
- .git/objects/24/e98633b9e4a31fd210c2eeae5c8987e2b1f57c +0 -0
- .git/objects/26/38390d41e532e1d942b6d36145cea208b8289b +0 -0
- .git/objects/28/47dd9f4c763d4f58fa09f95fce005822588792 +0 -0
- .git/objects/29/2aa49c25b414b74ef20340586f6fde4c4154ef +0 -0
- .git/objects/2a/ecfb9b33d51b09b0b79a53b00d89accf6023c8 +0 -0
- .git/objects/30/0e2fe4548b0675c0443ccb9e273f058d91552b +0 -0
- .git/objects/3c/da27cf7a62a6163b038c5c8bda73482d563af7 +0 -0
- .git/objects/3e/7449d6da3916718af8e8d3bc0576d35db991cc +0 -0
- .git/objects/3e/cd291b85d01d6260251009567cbf306098cc63 +0 -0
- .git/objects/40/63b9f1b2483d0cfcdb2a7fa1e2aa0f8e6b6a22 +0 -2
- .git/objects/43/8fe1376a06cab53e0bdf1629ad7533830ece54 +0 -0
- .git/objects/45/202f63795e9ece7313332d730d7359bf169048 +0 -0
- .git/objects/45/5f376dc5185586f8e5fed236f6547a9b95fe9f +0 -0
- .git/objects/46/52c55db06f32df93e1ca0d1f6b90067a4d50ff +0 -0
- .git/objects/47/d311ab16718476b46780b3c0b078cc2f0b5363 +0 -0
- .git/objects/48/35139bc257d0ce1d0497836ea233fedf0cf7e2 +0 -0
- .git/objects/4a/298f060025643a78be0da2181ccb19b4cf1a52 +0 -0
- .git/objects/4a/44ccd200d7965ebfafa79e32f781d70bce8618 +0 -0
- .git/objects/4c/721f452dadf9e303017cdc6e544e721dfb922d +0 -0
- .git/objects/4d/f12098552734b547892b5a3412149d90acf5df +0 -0
- .git/objects/4f/175ec45d22e03a80873da3b3a9547af0460d69 +0 -0
- .git/objects/4f/1ff6d693ee6adde85c30d4068b1898e2672e38 +0 -0
- .git/objects/4f/f337e4b4f256d3034a70d88887dc9c6c7caa02 +0 -0
- .git/objects/52/2e1c3f5f286ae06f58ab5cc2e6f796366914d9 +0 -0
- .git/objects/53/13510cdc184392e70393f3e99f0b99c9cf4b07 +0 -0
- .git/objects/53/847edbeebc9e1eb3e0bddcc0a726737aae2ff4 +0 -0
- .git/objects/54/78494c0fb874eb4112626912250e9d87b79782 +0 -0
- .git/objects/56/12275dd6ffd118605643ce5be0b09f82099ecf +0 -0
- .git/objects/61/41d3de631666d108a4cd10aa28f805e7ba2176 +0 -0
- .git/objects/61/a52a6564a3416abcfbde4f9c31ea003797be1c +0 -0
- .git/objects/62/9a884ee20ea72f3e529f09d17cf2c6bcdde59a +0 -0
- .git/objects/65/79867fd47b1f1d94d7f86b363290b9992dd3d5 +0 -0
- .git/objects/66/56027dc3dce02aeb380558b28a1155f9f56221 +0 -0
- .git/objects/66/d6fcea767d7fb1379a06649988656f59b2f11f +0 -0
- .git/objects/67/5a2f2488c4472fefe8c01d58af3036e8ea3646 +0 -0
- .git/objects/68/51843a6186387cc24e57013ecb48234c29d606 +0 -0
- .git/objects/68/83ffef5964a7e304ad31a36bc826b10b466630 +0 -0
- .git/objects/6b/fc4fdd895285d93151265e2a61a1f9b9bfeb23 +0 -0
- .git/objects/6c/0869f2a22f30604443d53c2193c5862f9631ab +0 -0
- .git/objects/6c/8c18a8b818bc289cdb5af64bf4d9c1965cd0bb +0 -2
- .git/objects/6d/05879d4c160a3f719b8a0e955ff0942d5c8cc5 +0 -0
- .git/objects/6d/165188630ed19e578141107a626e45266bde15 +0 -0
- .git/objects/6e/8321d8213769293fe28b366dceacdba4e1ae53 +0 -0
- .git/objects/6f/a39e12d18f8332b416a39022a17038b2fb2b79 +0 -0
- .git/objects/70/3dddb937f919e83e887796e5cde65a82e550b7 +0 -0
- .git/objects/70/bcd529437b15a83ecc1851515ceb5baee2c968 +0 -0
- .git/objects/71/2b09b10356caf10cdb2a164ac31f2fdca9e8df +0 -0
- .git/objects/72/17705dce1fb7641f1a6be9cad6a4c0c0bdef54 +0 -0
- .git/objects/72/2a2b31541c4b4eabd01df1cd9f78bf902b48f2 +0 -0
- .git/objects/74/0ee4f5f65869ebb2990d984a238c1b83bf2d2e +0 -0
- .git/objects/76/675f4e4a951b71830de8763b40f8dba5f0e329 +0 -0
- .git/objects/78/a0e7777e91f85a4304fd7b3ac57d1654496fae +0 -0
- .git/objects/7a/2351a44cd4ce936a35e2a9637da3626200abc7 +0 -0
- .git/objects/7b/cb5422cd40f863e38c1415e879c66b2b0f6ed0 +0 -0
- .git/objects/80/fa8421446fe3ef9facb790cf8e93e8bfa7bf86 +0 -0
- .git/objects/81/2ef37d3eaf8b52e4ffc3ad429fa230780b3d3e +0 -0
- .git/objects/82/d7fdd2beb79b6b64ab2da1d791d3a2b64d583f +0 -1
- .git/objects/87/d4c9ebcc955f31a4e125fb692e8f6b7e2e9004 +0 -0
- .git/objects/87/edbd2d1f2dbdfb5d64c9dcfb17cb330143aa7a +0 -0
- .git/objects/89/57f44e305c6c4cd64d0e8f4c6677f834cb810c +0 -2
- .git/objects/89/8a90dbe5babc16e488c790849f1d189814aacc +0 -0
- .git/objects/8c/2fccdebc495f29cbb18b641815020290b6d531 +0 -0
- .git/objects/8f/7de669deb74e7fb028bd0d8661d3ab19902ef2 +0 -0
- .git/objects/90/70debb5147ecc0efc58f48c3f5d1afa0a6d058 +0 -0
- .git/objects/91/af3b7f9fc304aa4d5593ab2dea81edd16c6842 +0 -0
- .git/objects/91/e75ebdffb1bd2868362c83269ac8757511a113 +0 -0
- .git/objects/92/cc82343d809b40274fc896aa639bcc6cdeef53 +0 -0
- .git/objects/94/a25f7f4cb416c083d265558da75d457237d671 +0 -0
- .git/objects/98/e9c322ec3ddf6150bdc7b6eab43d50dc68477f +0 -0
- .git/objects/99/d26651a87295a4967a9c662b4fc483dca54303 +0 -0
- .git/objects/99/f64fe8661dde8511c7581136ff1343df72ae11 +0 -0
- .git/objects/9c/0b1c3e999e338805b480e135fe7b2f0300f534 +0 -0
- .git/objects/9e/1b178c51649d878eeb1b99063594ed80903ce9 +0 -0
- .git/objects/a1/6305ecc5eeba77cae9e067f8491936ce9852f9 +0 -0
- .git/objects/a2/059f9bac3f3fdc5f58fa93ef828b03496807e3 +0 -0
- .git/objects/a2/6aa4fc4c3378ef756103f26ceb3618d2615ddb +0 -0
- .git/objects/a2/b3fd2fcf75b4e01fc46313f5b6b10d9574ea45 +0 -0
- .git/objects/a8/c116e2796299d870623c7c7bade3a482ced1e1 +0 -0
- .git/objects/a9/6353914fff11500d5e307c6a39379a7dc3f3a5 +0 -0
- .git/objects/ab/0e7004a39aedeffecd15a29948ef2983f8fedb +0 -0
- .git/objects/ab/2336f2f5c66697cfeff071f874c5171dc3e203 +0 -0
- .git/objects/ab/2e84e0513674a3feb40a625e67c826830cf955 +0 -0
- .git/objects/ae/098f9246f2cec2ef7487ab710dbb2ec4ba6f25 +0 -0
- .git/objects/ae/4da2d6bc50f83d660c0fe9839a280487f7ef87 +0 -0
- .git/objects/ae/7dc4cf2e4e4d808e632ce118b0d317e7e6d06b +0 -0
- .git/objects/ae/9c9580e50bff0e005fdf99e0a5a9ff6e76b91c +0 -0
- .git/objects/ae/b009618d2b8fb2c50ca54ea0a3657ffdb6c4ba +0 -0
- .git/objects/b3/24de33b5a21a01c9ae8b33636d5f1aca3efd31 +0 -0
- .git/objects/b5/320acd6bb7f62a174eccefe2ddc3eb1eff24e9 +0 -0
- .git/objects/b5/6828ec56fa75308c2f6c9db08ec414fd0b566d +0 -0
- .git/objects/b6/2c268663d053e57692cd9bf21f6c0c61a53411 +0 -0
- .git/objects/b8/1d5264f5b7448228120be9283b50ca1797bd02 +0 -0
- .git/objects/b9/210e2bbaff2e3b546ca3c65fc9d42fecef0f6b +0 -1
- .git/objects/bb/ab42af439de66ac98d4024416c8b32b3066e45 +0 -0
- .git/objects/bc/2ece3504ba0d8e65a40f223c8d04fc07b41fc7 +0 -0
- .git/objects/c0/3e8fe2975c8a6fc281915546747c07905a81a7 +0 -0
- .git/objects/c0/bdda06278a78d10a16e7df4dce2c73387c91be +0 -0
- .git/objects/c1/0d3d0df470652770af295bbeb9848e76daea05 +0 -0
- .git/objects/c2/574881c5be951d33c8df083325c241c6c83c55 +0 -0
- .git/objects/c2/d6ec54c49f9b6141f28e3b9b0276d7c71d18d2 +0 -0
- .git/objects/c2/f2fb023dbbe83b13b3a08bbf9eb7ee3539ae17 +0 -2
- .git/objects/c5/a8cf53296097c73cb02ed9b2e1aefb3ff4ccdc +0 -0
- .git/objects/c8/8a8dadb163234e72ffd8e29565200c537a0bc0 +0 -3
- .git/objects/c8/c228603f594ff421808257b643cc3a37aff7d3 +0 -0
- .git/objects/cb/3f5041c4acf866cff013ea916d12dc2482fe35 +0 -0
- .git/objects/cc/91ad25539ed2c756aa3de1b07cacece6ec0137 +0 -0
- .git/objects/d1/49cd9c1d61f461a7c0d6023ae9028f0ee525a9 +0 -0
- .git/objects/d5/292a1122dd0382ddb15b1c589bfe2370dd9062 +0 -0
- .git/objects/d5/5e55c84565f30bca7b4ef17551b9362a752d7f +0 -0
- .git/objects/d6/3d373dafc2d3cc9ea97033e0a05d90185118f5 +0 -0
- .git/objects/d6/c28b29f40cca12d8e80c02e5539e0ccdb5e69e +0 -0
- .git/objects/d7/238aa2b4808051f8d09b263c5c24d0921d1509 +0 -1
- .git/objects/d7/6b40fe82c1b34d7f1eadb11a4919aed78b965b +0 -0
- .git/objects/d8/1ab4149f5cf0ed537300961b50b741117d5d0d +0 -0
- .git/objects/d8/4dc6f797e9140db9540ca9de0fdef62238620c +0 -0
- .git/objects/d8/b3f6cbf0c04e3481a87fcd0d588f490d9fdac7 +0 -0
- .git/objects/db/dfb17058375783a115dec9b8667166daeafea7 +0 -0
- .git/objects/db/ef36011c0e082be9e83554b12b2e6ce5449890 +0 -0
- .git/objects/dc/26d426cf68c8b82ca3aeda0e7656b9c63a2a17 +0 -0
- .git/objects/e0/3c1b89624ed6163c875c84c114ce87ffb33e9f +0 -0
- .git/objects/e1/801f544ddfb099ec8b7ffea3d7d0b6226f07cd +0 -0
- .git/objects/e3/cf7976790f02529fae084d3d698133dfdf33cb +0 -0
- .git/objects/e5/c4125bfafa8ca31149ef216e5188a82cdfd9bc +0 -0
- .git/objects/e6/0fd8a2ed55b272863b70676def2feb34a2f5ab +0 -0
- .git/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391 +0 -0
- .git/objects/e9/b540e3f95a3bddb31f9c7154ddc8d1416a5a49 +0 -0
- .git/objects/ea/1df7109d325e658658d32745c75adc6fab59de +0 -0
- .git/objects/eb/6c739b8f3e5b04d92d961f586cab2e6aed9299 +0 -0
- .git/objects/ed/2445f60de723b9c2f677f04890f42005b7cf75 +0 -0
- .git/objects/ef/3861fba8550a65b4bdc9705c7a9ae6c68f7811 +0 -0
- .git/objects/f2/8d82d529c1cd6185b393d2e779364550f7ece4 +0 -0
- .git/objects/f3/872867a1dbe7db3eb03d5e3817b65276260bb9 +0 -0
- .git/objects/f3/c2f22db356e7aaf2700677b764eb9c44abce8b +0 -0
- .git/objects/f7/b8019fae044e97766b5046d48b792e56263d9f +0 -2
- .git/objects/f8/28fe560a37bfee17a4e3af48a1ac2849e7bd47 +0 -0
- .git/objects/f9/099a73a609541d9d411193d2fa975852080cdf +0 -0
- .git/objects/f9/a1fcc542a53abc04564661c174bf85015ae4c9 +0 -2
- .git/objects/fb/bb61d4888712eae9a07c93820ee6dcfbf068db +0 -0
- .git/objects/fb/cbd444bb66d87e9e116dfe42331e4f9cff1b5a +0 -0
- .git/objects/ff/2f55840120e843740fab47d50dcdc7cedef91d +0 -0
- .git/objects/ff/ba5c4ae674142c7fdace47e34357ba8504ba58 +0 -0
- .git/objects/pack/pack-286afde1b841483a0d40e4c4d4bc844eb78906e1.idx +0 -0
- .git/objects/pack/pack-286afde1b841483a0d40e4c4d4bc844eb78906e1.pack +0 -0
- .git/objects/pack/pack-286afde1b841483a0d40e4c4d4bc844eb78906e1.rev +0 -0
- .git/packed-refs +0 -2
- .git/refs/heads/ISS14 +0 -1
- .git/refs/heads/PR5 +0 -1
- .git/refs/heads/distr +0 -1
- .git/refs/heads/github_workflow +0 -1
- .git/refs/heads/main +0 -1
- .git/refs/heads/pr10 +0 -1
- .git/refs/heads/pr11 +0 -1
- .git/refs/heads/pr12 +0 -1
- .git/refs/heads/pr13 +0 -1
- .git/refs/heads/pr14 +0 -1
- .git/refs/heads/pr15 +0 -1
- .git/refs/heads/pr2 +0 -1
- .git/refs/heads/pr3 +0 -1
- .git/refs/heads/pr4 +0 -1
- .git/refs/heads/pr6 +0 -1
- .git/refs/heads/pr8 +0 -1
- .git/refs/heads/pr9 +0 -1
- .git/refs/remotes/origin/HEAD +0 -1
- .git/refs/remotes/origin/ISS14 +0 -1
- .git/refs/remotes/origin/PR5 +0 -1
- .git/refs/remotes/origin/distr +0 -1
- .git/refs/remotes/origin/github_workflow +0 -1
- .git/refs/remotes/origin/main +0 -1
- .git/refs/remotes/origin/pr10 +0 -1
- .git/refs/remotes/origin/pr12 +0 -1
- .git/refs/remotes/origin/pr13 +0 -1
- .git/refs/remotes/origin/pr14 +0 -1
- .git/refs/remotes/origin/pr15 +0 -1
- .git/refs/remotes/origin/pr2 +0 -1
- .git/refs/remotes/origin/pr3 +0 -1
- .git/refs/remotes/origin/pr4 +0 -1
- .git/refs/remotes/origin/pr6 +0 -1
- .git/refs/remotes/origin/pr8 +0 -1
- .git/refs/remotes/origin/pr9 +0 -1
- .github/workflows/code-style.yml +0 -16
- .github/workflows/cr.yml +0 -99
- .gitignore +0 -178
- CONTRIBUTING.md +0 -44
- Makefile +0 -23
- README.md +0 -6
- ai_cr-0.1.0.dist-info/LICENSE +0 -21
- ai_cr-0.1.0.dist-info/METADATA +0 -32
- ai_cr-0.1.0.dist-info/RECORD +0 -277
- ai_cr-0.1.0.dist-info/entry_points.txt +0 -3
- cr-github-workflow-example.yml +0 -100
- cr-prompt.j2 +0 -18
- cr.py +0 -71
- publish.py +0 -16
- pyproject.toml +0 -57
- requirements.txt +0 -3
- /LICENSE → /ai_cr-0.4.2.dist-info/LICENSE +0 -0
- {ai_cr-0.1.0.dist-info → ai_cr-0.4.2.dist-info}/WHEEL +0 -0
@@ -0,0 +1,108 @@
|
|
1
|
+
import json
|
2
|
+
import logging
|
3
|
+
from dataclasses import dataclass, field, asdict
|
4
|
+
from datetime import datetime
|
5
|
+
from enum import StrEnum
|
6
|
+
|
7
|
+
import microcore as mc
|
8
|
+
|
9
|
+
from .constants import JSON_REPORT_FILE_NAME
|
10
|
+
from .project_config import ProjectConfig
|
11
|
+
from .utils import syntax_hint
|
12
|
+
|
13
|
+
|
14
|
+
@dataclass
|
15
|
+
class Issue:
|
16
|
+
@dataclass
|
17
|
+
class AffectedCode:
|
18
|
+
start_line: int = field()
|
19
|
+
end_line: int | None = field(default=None)
|
20
|
+
file: str = field(default="")
|
21
|
+
proposal: str = field(default="")
|
22
|
+
affected_code: str = field(default="")
|
23
|
+
|
24
|
+
@property
|
25
|
+
def syntax_hint(self) -> str:
|
26
|
+
return syntax_hint(self.file)
|
27
|
+
|
28
|
+
id: str = field()
|
29
|
+
title: str = field()
|
30
|
+
details: str = field(default="")
|
31
|
+
severity: int | None = field(default=None)
|
32
|
+
confidence: int | None = field(default=None)
|
33
|
+
tags: list[str] = field(default_factory=list)
|
34
|
+
file: str = field(default="")
|
35
|
+
affected_lines: list[AffectedCode] = field(default_factory=list)
|
36
|
+
|
37
|
+
def __post_init__(self):
|
38
|
+
self.affected_lines = [
|
39
|
+
Issue.AffectedCode(**dict(file=self.file) | i)
|
40
|
+
for i in self.affected_lines
|
41
|
+
]
|
42
|
+
|
43
|
+
def github_code_link(self, github_env: dict) -> str:
|
44
|
+
url = (
|
45
|
+
f"https://github.com/{github_env['github_repo']}"
|
46
|
+
f"/blob/{github_env['github_pr_sha_or_branch']}"
|
47
|
+
f"/{self.file}"
|
48
|
+
)
|
49
|
+
if self.affected_lines:
|
50
|
+
url += f"#L{self.affected_lines[0].start_line}"
|
51
|
+
if self.affected_lines[0].end_line:
|
52
|
+
url += f"-L{self.affected_lines[0].end_line}"
|
53
|
+
return url
|
54
|
+
|
55
|
+
|
56
|
+
@dataclass
|
57
|
+
class Report:
|
58
|
+
class Format(StrEnum):
|
59
|
+
MARKDOWN = "md"
|
60
|
+
|
61
|
+
issues: dict = field(default_factory=dict)
|
62
|
+
summary: str = field(default="")
|
63
|
+
number_of_processed_files: int = field(default=0)
|
64
|
+
total_issues: int = field(init=False)
|
65
|
+
created_at: str = field(default_factory=lambda: datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
|
66
|
+
model: str = field(default_factory=lambda: mc.config().MODEL)
|
67
|
+
|
68
|
+
@property
|
69
|
+
def plain_issues(self):
|
70
|
+
return [
|
71
|
+
issue
|
72
|
+
for file, issues in self.issues.items()
|
73
|
+
for issue in issues
|
74
|
+
]
|
75
|
+
|
76
|
+
def __post_init__(self):
|
77
|
+
issue_id: int = 0
|
78
|
+
for file in self.issues.keys():
|
79
|
+
self.issues[file] = [
|
80
|
+
Issue(
|
81
|
+
**{
|
82
|
+
"id": (issue_id := issue_id + 1),
|
83
|
+
"file": file,
|
84
|
+
} | issue
|
85
|
+
)
|
86
|
+
for issue in self.issues[file]
|
87
|
+
]
|
88
|
+
self.total_issues = issue_id
|
89
|
+
|
90
|
+
def save(self, file_name: str = ""):
|
91
|
+
file_name = file_name or JSON_REPORT_FILE_NAME
|
92
|
+
with open(file_name, "w") as f:
|
93
|
+
json.dump(asdict(self), f, indent=4)
|
94
|
+
logging.info(f"Report saved to {mc.utils.file_link(file_name)}")
|
95
|
+
|
96
|
+
@staticmethod
|
97
|
+
def load(file_name: str = ""):
|
98
|
+
with open(file_name or JSON_REPORT_FILE_NAME, "r") as f:
|
99
|
+
data = json.load(f)
|
100
|
+
data.pop("total_issues", None)
|
101
|
+
return Report(**data)
|
102
|
+
|
103
|
+
def render(
|
104
|
+
self, cfg: ProjectConfig = None, format: Format = Format.MARKDOWN
|
105
|
+
) -> str:
|
106
|
+
cfg = cfg or ProjectConfig.load()
|
107
|
+
template = getattr(cfg, f"report_template_{format}")
|
108
|
+
return mc.prompt(template, report=self, **cfg.prompt_vars)
|
ai_code_review/utils.py
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
from pathlib import Path
|
2
|
+
|
3
|
+
_EXT_TO_HINT: dict[str, str] = {
|
4
|
+
# scripting & languages
|
5
|
+
".py": "python",
|
6
|
+
".js": "javascript",
|
7
|
+
".ts": "typescript",
|
8
|
+
".java": "java",
|
9
|
+
".c": "c",
|
10
|
+
".cpp": "cpp",
|
11
|
+
".cc": "cpp",
|
12
|
+
".cxx": "cpp",
|
13
|
+
".h": "cpp",
|
14
|
+
".hpp": "cpp",
|
15
|
+
".cs": "csharp",
|
16
|
+
".rb": "ruby",
|
17
|
+
".go": "go",
|
18
|
+
".rs": "rust",
|
19
|
+
".swift": "swift",
|
20
|
+
".kt": "kotlin",
|
21
|
+
".scala": "scala",
|
22
|
+
".dart": "dart",
|
23
|
+
".php": "php",
|
24
|
+
".pl": "perl",
|
25
|
+
".pm": "perl",
|
26
|
+
".lua": "lua",
|
27
|
+
# web & markup
|
28
|
+
".html": "html",
|
29
|
+
".htm": "html",
|
30
|
+
".css": "css",
|
31
|
+
".scss": "scss",
|
32
|
+
".less": "less",
|
33
|
+
".json": "json",
|
34
|
+
".xml": "xml",
|
35
|
+
".yaml": "yaml",
|
36
|
+
".yml": "yaml",
|
37
|
+
".toml": "toml",
|
38
|
+
".ini": "ini",
|
39
|
+
".csv": "csv",
|
40
|
+
".md": "markdown",
|
41
|
+
".rst": "rest",
|
42
|
+
# shell & config
|
43
|
+
".sh": "bash",
|
44
|
+
".bash": "bash",
|
45
|
+
".zsh": "bash",
|
46
|
+
".fish": "bash",
|
47
|
+
".ps1": "powershell",
|
48
|
+
".dockerfile": "dockerfile",
|
49
|
+
# build & CI
|
50
|
+
".makefile": "makefile",
|
51
|
+
".mk": "makefile",
|
52
|
+
"CMakeLists.txt": "cmake",
|
53
|
+
"Dockerfile": "dockerfile",
|
54
|
+
".gradle": "groovy",
|
55
|
+
".travis.yml": "yaml",
|
56
|
+
# data & queries
|
57
|
+
".sql": "sql",
|
58
|
+
".graphql": "graphql",
|
59
|
+
".proto": "protobuf",
|
60
|
+
".yara": "yara",
|
61
|
+
}
|
62
|
+
|
63
|
+
|
64
|
+
def syntax_hint(file_name: str) -> str:
|
65
|
+
"""
|
66
|
+
Get the syntax hint for a file based on its extension.
|
67
|
+
"""
|
68
|
+
p = Path(file_name)
|
69
|
+
ext = p.suffix.lower()
|
70
|
+
if not ext:
|
71
|
+
name = p.name.lower()
|
72
|
+
if name == "dockerfile":
|
73
|
+
return "dockerfile"
|
74
|
+
return ""
|
75
|
+
return _EXT_TO_HINT.get(ext, ext.lstrip("."))
|
@@ -0,0 +1,161 @@
|
|
1
|
+
Metadata-Version: 2.3
|
2
|
+
Name: ai-cr
|
3
|
+
Version: 0.4.2
|
4
|
+
Summary: LLM-agnostic GitHub AI Code Review Tool with integration to GitHub actions
|
5
|
+
License: MIT
|
6
|
+
Keywords: ai,coding,assistant,llm,code review,github,automation,devops,developer tools,github actions,workflows
|
7
|
+
Author: Nayjest
|
8
|
+
Author-email: mail@vitaliy.in
|
9
|
+
Requires-Python: >=3.11,<4.0
|
10
|
+
Classifier: Environment :: Console
|
11
|
+
Classifier: Intended Audience :: Developers
|
12
|
+
Classifier: License :: OSI Approved :: MIT License
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
16
|
+
Classifier: Programming Language :: Python :: 3.13
|
17
|
+
Classifier: Topic :: Software Development
|
18
|
+
Requires-Dist: GitPython (>=3.1.44,<4.0.0)
|
19
|
+
Requires-Dist: ai-microcore (>=4.0.0.dev11,<5.0.0)
|
20
|
+
Requires-Dist: anthropic (>=0.49.0,<0.50.0)
|
21
|
+
Requires-Dist: async-typer (>=0.1.8,<0.2.0)
|
22
|
+
Requires-Dist: google-generativeai (>=0.8.5,<0.9.0)
|
23
|
+
Requires-Dist: typer (>=0.9.4,<0.10.0)
|
24
|
+
Requires-Dist: unidiff (>=0.7.5,<0.8.0)
|
25
|
+
Project-URL: Homepage, https://github.com/Nayjest/github-ai-code-review
|
26
|
+
Project-URL: Repository, https://github.com/Nayjest/github-ai-code-review
|
27
|
+
Description-Content-Type: text/markdown
|
28
|
+
|
29
|
+
<p align="right">
|
30
|
+
<a href="https://pypi.org/project/ai-code-review/" target="_blank"><img src="https://badge.fury.io/py/ai-code-review.svg" alt="PYPI Release"></a>
|
31
|
+
<a href="https://github.com/Nayjest/ai-code-review/actions/workflows/code-style.yml" target="_blank"><img src="https://github.com/Nayjest/ai-code-review/actions/workflows/code-style.yml/badge.svg" alt="Pylint"></a>
|
32
|
+
<a href="https://github.com/Nayjest/ai-code-review/actions/workflows/tests.yml" target="_blank"><img src="https://github.com/Nayjest/ai-code-review/actions/workflows/tests.yml/badge.svg" alt="Tests"></a>
|
33
|
+
<a href="https://github.com/Nayjest/ai-code-review/blob/main/LICENSE" target="_blank"><img src="https://img.shields.io/static/v1?label=license&message=MIT&color=d08aff" alt="License"></a>
|
34
|
+
</p>
|
35
|
+
|
36
|
+
# 🤖 AI Code Review Tool
|
37
|
+
|
38
|
+
An AI-powered GitHub code review tool that uses LLMs to detect high-confidence, high-impact issues—such as security vulnerabilities, bugs, and maintainability concerns.
|
39
|
+
|
40
|
+
## ✨ Features
|
41
|
+
|
42
|
+
- Automatically reviews pull requests via GitHub Actions
|
43
|
+
- Focuses on critical issues (e.g., bugs, security risks, design flaws)
|
44
|
+
- Posts review results as a comment on your PR
|
45
|
+
- Can be used locally; works with both local and remote Git repositories
|
46
|
+
- Optional, fun AI-generated code awards 🏆
|
47
|
+
- Easily configurable via [`.ai-code-review.toml`](ai_code_review/.ai-code-review.toml)
|
48
|
+
- Extremely fast, parallel LLM usage
|
49
|
+
- Model-agnostic (OpenAI, Anthropic, Google, local PyTorch inference, etc.)
|
50
|
+
|
51
|
+
See code review in action: [example](https://github.com/Nayjest/github-ai-code-review/pull/28#issuecomment-2891611236)
|
52
|
+
|
53
|
+
## 🚀 Quickstart
|
54
|
+
|
55
|
+
### 1. Review Pull Requests via GitHub Actions
|
56
|
+
|
57
|
+
Create a `.github/workflows/ai-code-review.yml` file:
|
58
|
+
|
59
|
+
```yaml
|
60
|
+
name: AI Code Review
|
61
|
+
on: { pull_request: { types: [opened, synchronize, reopened] } }
|
62
|
+
jobs:
|
63
|
+
review:
|
64
|
+
runs-on: ubuntu-latest
|
65
|
+
permissions: { contents: read, pull-requests: write } # 'write' for leaving the summary comment
|
66
|
+
steps:
|
67
|
+
- uses: actions/checkout@v4
|
68
|
+
with: { fetch-depth: 0 }
|
69
|
+
- name: Set up Python
|
70
|
+
uses: actions/setup-python@v5
|
71
|
+
with: { python-version: "3.13" }
|
72
|
+
- name: Install AI Code Review tool
|
73
|
+
run: pip install ai-code-review==0.4.1
|
74
|
+
- name: Run AI code review
|
75
|
+
env:
|
76
|
+
LLM_API_KEY: ${{ secrets.LLM_API_KEY }}
|
77
|
+
LLM_API_TYPE: openai
|
78
|
+
MODEL: "gpt-4.1"
|
79
|
+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
80
|
+
run: |
|
81
|
+
ai-code-review
|
82
|
+
ai-code-review github-comment --token ${{ secrets.GITHUB_TOKEN }}
|
83
|
+
- uses: actions/upload-artifact@v4
|
84
|
+
with:
|
85
|
+
name: ai-code-review-results
|
86
|
+
path: |
|
87
|
+
code-review-report.txt
|
88
|
+
code-review-report.json
|
89
|
+
```
|
90
|
+
|
91
|
+
> ⚠️ Make sure to add `LLM_API_KEY` to your repository’s GitHub secrets.
|
92
|
+
|
93
|
+
💪 Done!
|
94
|
+
PRs to your repository will now receive AI code reviews automatically. ✨
|
95
|
+
|
96
|
+
### 2. Run Locally
|
97
|
+
|
98
|
+
Install and run:
|
99
|
+
|
100
|
+
```bash
|
101
|
+
# Prerequisites: Python 3.11+
|
102
|
+
pip install ai-code-review
|
103
|
+
|
104
|
+
# One-time setup using interactive wizard (saves configuration in ~/.env.ai-code-review)
|
105
|
+
ai-code-review setup
|
106
|
+
|
107
|
+
# Run review on committed changes in current branch vs main
|
108
|
+
ai-code-review
|
109
|
+
```
|
110
|
+
|
111
|
+
To review a remote repository:
|
112
|
+
|
113
|
+
```bash
|
114
|
+
ai-code-review remote --url https://github.com/owner/repo --branch feature-branch
|
115
|
+
```
|
116
|
+
|
117
|
+
## 🔧 Configuration
|
118
|
+
|
119
|
+
Change behavior via `.ai-code-review.toml`:
|
120
|
+
|
121
|
+
- Prompt templates, filtering and post-processing using Python code snippets
|
122
|
+
- Tagging, severity, and confidence settings
|
123
|
+
- Custom AI awards for developer brilliance
|
124
|
+
- Output customization
|
125
|
+
|
126
|
+
You can override the default config by placing `.ai-code-review.toml` in your repo root.
|
127
|
+
|
128
|
+
|
129
|
+
See default configuration [here](ai_code_review/.ai-code-review.toml).
|
130
|
+
|
131
|
+
## 💻 Development Setup
|
132
|
+
|
133
|
+
Install dependencies:
|
134
|
+
|
135
|
+
```bash
|
136
|
+
make install
|
137
|
+
```
|
138
|
+
|
139
|
+
Format code and check style:
|
140
|
+
|
141
|
+
```bash
|
142
|
+
make black
|
143
|
+
make cs
|
144
|
+
```
|
145
|
+
|
146
|
+
Run tests:
|
147
|
+
|
148
|
+
```bash
|
149
|
+
pytest
|
150
|
+
```
|
151
|
+
|
152
|
+
## 🤝 Contributing
|
153
|
+
|
154
|
+
We ❤️ contributions! See [CONTRIBUTING.md](CONTRIBUTING.md).
|
155
|
+
|
156
|
+
## 📝 License
|
157
|
+
|
158
|
+
Licensed under the [MIT License](LICENSE).
|
159
|
+
|
160
|
+
© 2025 [Vitalii Stepanenko](mailto:mail@vitaliy.in)
|
161
|
+
|
@@ -0,0 +1,14 @@
|
|
1
|
+
ai_code_review/.ai-code-review.toml,sha256=MovvzoXNuaV8XsJfwYYde7oT69NNfnN_P_vRvG-dBvk,10332
|
2
|
+
ai_code_review/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
3
|
+
ai_code_review/bootstrap.py,sha256=vhAWjrfhkyyA504YusXhBlndsXd_bg2RP9hQbfnvM1M,1280
|
4
|
+
ai_code_review/cli.py,sha256=lulkEEUmQ1Fn3j3aQ0ZXc6aPHPcQDsr4YqA_C6gFFH4,3409
|
5
|
+
ai_code_review/constants.py,sha256=K9mNxTq9seTG3aVm__3r1lXb5oCOQjH24Cl3hfX9FsE,281
|
6
|
+
ai_code_review/core.py,sha256=LhstEanCpMD0rVEYja0EQ4GuwB47RXGJJNOTkD6WqYk,3888
|
7
|
+
ai_code_review/project_config.py,sha256=RDbplmncALKw0zgqSG8POofi300z0DPvtF33wt7_1Sk,3651
|
8
|
+
ai_code_review/report_struct.py,sha256=N-EnNMwBY9LyJ9sdFHpUzn2fwBvxo5TZYYiJagBl8Po,3488
|
9
|
+
ai_code_review/utils.py,sha256=DLzX9kILl5ABAsuwqFJk_3kItjgzzeTUrgZ3RMnDgAY,1713
|
10
|
+
ai_cr-0.4.2.dist-info/entry_points.txt,sha256=fQYGUz6CVCClhei9kNCTtJUX6ia-dTca6p1sZ9pnst8,48
|
11
|
+
ai_cr-0.4.2.dist-info/LICENSE,sha256=XATf3zv-CppUSJqI18KLhwnPEomUXEl5WbBzFyb9OSU,1096
|
12
|
+
ai_cr-0.4.2.dist-info/METADATA,sha256=M8tRAuEfeiNsv4uBFmZGnjbth8nTKDVB_AITLyCpe2U,5302
|
13
|
+
ai_cr-0.4.2.dist-info/WHEEL,sha256=fGIA9gx4Qxk2KDKeNJCbOEwSrmLtjWCwzBz351GyrPQ,88
|
14
|
+
ai_cr-0.4.2.dist-info/RECORD,,
|
.git/COMMIT_EDITMSG
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
missing changes to prev. commit
|
.git/FETCH_HEAD
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
70bcd529437b15a83ecc1851515ceb5baee2c968 branch 'main' of github.com:Nayjest/github-ai-code-review
|
.git/ORIG_HEAD
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
c5a8cf53296097c73cb02ed9b2e1aefb3ff4ccdc
|
.git/config
DELETED
@@ -1,57 +0,0 @@
|
|
1
|
-
[core]
|
2
|
-
repositoryformatversion = 0
|
3
|
-
filemode = false
|
4
|
-
bare = false
|
5
|
-
logallrefupdates = true
|
6
|
-
ignorecase = true
|
7
|
-
[remote "origin"]
|
8
|
-
url = git@github.com:Nayjest/github-ai-code-review.git
|
9
|
-
fetch = +refs/heads/*:refs/remotes/origin/*
|
10
|
-
[branch "main"]
|
11
|
-
remote = origin
|
12
|
-
merge = refs/heads/main
|
13
|
-
[branch "github_workflow"]
|
14
|
-
remote = origin
|
15
|
-
merge = refs/heads/github_workflow
|
16
|
-
[branch "pr2"]
|
17
|
-
remote = origin
|
18
|
-
merge = refs/heads/pr2
|
19
|
-
[branch "pr3"]
|
20
|
-
remote = origin
|
21
|
-
merge = refs/heads/pr3
|
22
|
-
[branch "pr4"]
|
23
|
-
remote = origin
|
24
|
-
merge = refs/heads/pr4
|
25
|
-
[branch "PR5"]
|
26
|
-
remote = origin
|
27
|
-
merge = refs/heads/PR5
|
28
|
-
[branch "pr6"]
|
29
|
-
remote = origin
|
30
|
-
merge = refs/heads/pr6
|
31
|
-
[branch "pr8"]
|
32
|
-
remote = origin
|
33
|
-
merge = refs/heads/pr8
|
34
|
-
[branch "pr9"]
|
35
|
-
remote = origin
|
36
|
-
merge = refs/heads/pr9
|
37
|
-
[branch "pr10"]
|
38
|
-
remote = origin
|
39
|
-
merge = refs/heads/pr10
|
40
|
-
[branch "pr12"]
|
41
|
-
remote = origin
|
42
|
-
merge = refs/heads/pr12
|
43
|
-
[branch "pr13"]
|
44
|
-
remote = origin
|
45
|
-
merge = refs/heads/pr13
|
46
|
-
[branch "pr14"]
|
47
|
-
remote = origin
|
48
|
-
merge = refs/heads/pr14
|
49
|
-
[branch "pr15"]
|
50
|
-
remote = origin
|
51
|
-
merge = refs/heads/pr15
|
52
|
-
[branch "ISS14"]
|
53
|
-
remote = origin
|
54
|
-
merge = refs/heads/ISS14
|
55
|
-
[branch "distr"]
|
56
|
-
remote = origin
|
57
|
-
merge = refs/heads/distr
|
.git/description
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
Unnamed repository; edit this file 'description' to name the repository.
|
.git/hooks/applypatch-msg.sample
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
#!/bin/sh
|
2
|
-
#
|
3
|
-
# An example hook script to check the commit log message taken by
|
4
|
-
# applypatch from an e-mail message.
|
5
|
-
#
|
6
|
-
# The hook should exit with non-zero status after issuing an
|
7
|
-
# appropriate message if it wants to stop the commit. The hook is
|
8
|
-
# allowed to edit the commit message file.
|
9
|
-
#
|
10
|
-
# To enable this hook, rename this file to "applypatch-msg".
|
11
|
-
|
12
|
-
. git-sh-setup
|
13
|
-
commitmsg="$(git rev-parse --git-path hooks/commit-msg)"
|
14
|
-
test -x "$commitmsg" && exec "$commitmsg" ${1+"$@"}
|
15
|
-
:
|
.git/hooks/commit-msg.sample
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
#!/bin/sh
|
2
|
-
#
|
3
|
-
# An example hook script to check the commit log message.
|
4
|
-
# Called by "git commit" with one argument, the name of the file
|
5
|
-
# that has the commit message. The hook should exit with non-zero
|
6
|
-
# status after issuing an appropriate message if it wants to stop the
|
7
|
-
# commit. The hook is allowed to edit the commit message file.
|
8
|
-
#
|
9
|
-
# To enable this hook, rename this file to "commit-msg".
|
10
|
-
|
11
|
-
# Uncomment the below to add a Signed-off-by line to the message.
|
12
|
-
# Doing this in a hook is a bad idea in general, but the prepare-commit-msg
|
13
|
-
# hook is more suited to it.
|
14
|
-
#
|
15
|
-
# SOB=$(git var GIT_AUTHOR_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p')
|
16
|
-
# grep -qs "^$SOB" "$1" || echo "$SOB" >> "$1"
|
17
|
-
|
18
|
-
# This example catches duplicate Signed-off-by lines.
|
19
|
-
|
20
|
-
test "" = "$(grep '^Signed-off-by: ' "$1" |
|
21
|
-
sort | uniq -c | sed -e '/^[ ]*1[ ]/d')" || {
|
22
|
-
echo >&2 Duplicate Signed-off-by lines.
|
23
|
-
exit 1
|
24
|
-
}
|
@@ -1,174 +0,0 @@
|
|
1
|
-
#!/usr/bin/perl
|
2
|
-
|
3
|
-
use strict;
|
4
|
-
use warnings;
|
5
|
-
use IPC::Open2;
|
6
|
-
|
7
|
-
# An example hook script to integrate Watchman
|
8
|
-
# (https://facebook.github.io/watchman/) with git to speed up detecting
|
9
|
-
# new and modified files.
|
10
|
-
#
|
11
|
-
# The hook is passed a version (currently 2) and last update token
|
12
|
-
# formatted as a string and outputs to stdout a new update token and
|
13
|
-
# all files that have been modified since the update token. Paths must
|
14
|
-
# be relative to the root of the working tree and separated by a single NUL.
|
15
|
-
#
|
16
|
-
# To enable this hook, rename this file to "query-watchman" and set
|
17
|
-
# 'git config core.fsmonitor .git/hooks/query-watchman'
|
18
|
-
#
|
19
|
-
my ($version, $last_update_token) = @ARGV;
|
20
|
-
|
21
|
-
# Uncomment for debugging
|
22
|
-
# print STDERR "$0 $version $last_update_token\n";
|
23
|
-
|
24
|
-
# Check the hook interface version
|
25
|
-
if ($version ne 2) {
|
26
|
-
die "Unsupported query-fsmonitor hook version '$version'.\n" .
|
27
|
-
"Falling back to scanning...\n";
|
28
|
-
}
|
29
|
-
|
30
|
-
my $git_work_tree = get_working_dir();
|
31
|
-
|
32
|
-
my $retry = 1;
|
33
|
-
|
34
|
-
my $json_pkg;
|
35
|
-
eval {
|
36
|
-
require JSON::XS;
|
37
|
-
$json_pkg = "JSON::XS";
|
38
|
-
1;
|
39
|
-
} or do {
|
40
|
-
require JSON::PP;
|
41
|
-
$json_pkg = "JSON::PP";
|
42
|
-
};
|
43
|
-
|
44
|
-
launch_watchman();
|
45
|
-
|
46
|
-
sub launch_watchman {
|
47
|
-
my $o = watchman_query();
|
48
|
-
if (is_work_tree_watched($o)) {
|
49
|
-
output_result($o->{clock}, @{$o->{files}});
|
50
|
-
}
|
51
|
-
}
|
52
|
-
|
53
|
-
sub output_result {
|
54
|
-
my ($clockid, @files) = @_;
|
55
|
-
|
56
|
-
# Uncomment for debugging watchman output
|
57
|
-
# open (my $fh, ">", ".git/watchman-output.out");
|
58
|
-
# binmode $fh, ":utf8";
|
59
|
-
# print $fh "$clockid\n@files\n";
|
60
|
-
# close $fh;
|
61
|
-
|
62
|
-
binmode STDOUT, ":utf8";
|
63
|
-
print $clockid;
|
64
|
-
print "\0";
|
65
|
-
local $, = "\0";
|
66
|
-
print @files;
|
67
|
-
}
|
68
|
-
|
69
|
-
sub watchman_clock {
|
70
|
-
my $response = qx/watchman clock "$git_work_tree"/;
|
71
|
-
die "Failed to get clock id on '$git_work_tree'.\n" .
|
72
|
-
"Falling back to scanning...\n" if $? != 0;
|
73
|
-
|
74
|
-
return $json_pkg->new->utf8->decode($response);
|
75
|
-
}
|
76
|
-
|
77
|
-
sub watchman_query {
|
78
|
-
my $pid = open2(\*CHLD_OUT, \*CHLD_IN, 'watchman -j --no-pretty')
|
79
|
-
or die "open2() failed: $!\n" .
|
80
|
-
"Falling back to scanning...\n";
|
81
|
-
|
82
|
-
# In the query expression below we're asking for names of files that
|
83
|
-
# changed since $last_update_token but not from the .git folder.
|
84
|
-
#
|
85
|
-
# To accomplish this, we're using the "since" generator to use the
|
86
|
-
# recency index to select candidate nodes and "fields" to limit the
|
87
|
-
# output to file names only. Then we're using the "expression" term to
|
88
|
-
# further constrain the results.
|
89
|
-
my $last_update_line = "";
|
90
|
-
if (substr($last_update_token, 0, 1) eq "c") {
|
91
|
-
$last_update_token = "\"$last_update_token\"";
|
92
|
-
$last_update_line = qq[\n"since": $last_update_token,];
|
93
|
-
}
|
94
|
-
my $query = <<" END";
|
95
|
-
["query", "$git_work_tree", {$last_update_line
|
96
|
-
"fields": ["name"],
|
97
|
-
"expression": ["not", ["dirname", ".git"]]
|
98
|
-
}]
|
99
|
-
END
|
100
|
-
|
101
|
-
# Uncomment for debugging the watchman query
|
102
|
-
# open (my $fh, ">", ".git/watchman-query.json");
|
103
|
-
# print $fh $query;
|
104
|
-
# close $fh;
|
105
|
-
|
106
|
-
print CHLD_IN $query;
|
107
|
-
close CHLD_IN;
|
108
|
-
my $response = do {local $/; <CHLD_OUT>};
|
109
|
-
|
110
|
-
# Uncomment for debugging the watch response
|
111
|
-
# open ($fh, ">", ".git/watchman-response.json");
|
112
|
-
# print $fh $response;
|
113
|
-
# close $fh;
|
114
|
-
|
115
|
-
die "Watchman: command returned no output.\n" .
|
116
|
-
"Falling back to scanning...\n" if $response eq "";
|
117
|
-
die "Watchman: command returned invalid output: $response\n" .
|
118
|
-
"Falling back to scanning...\n" unless $response =~ /^\{/;
|
119
|
-
|
120
|
-
return $json_pkg->new->utf8->decode($response);
|
121
|
-
}
|
122
|
-
|
123
|
-
sub is_work_tree_watched {
|
124
|
-
my ($output) = @_;
|
125
|
-
my $error = $output->{error};
|
126
|
-
if ($retry > 0 and $error and $error =~ m/unable to resolve root .* directory (.*) is not watched/) {
|
127
|
-
$retry--;
|
128
|
-
my $response = qx/watchman watch "$git_work_tree"/;
|
129
|
-
die "Failed to make watchman watch '$git_work_tree'.\n" .
|
130
|
-
"Falling back to scanning...\n" if $? != 0;
|
131
|
-
$output = $json_pkg->new->utf8->decode($response);
|
132
|
-
$error = $output->{error};
|
133
|
-
die "Watchman: $error.\n" .
|
134
|
-
"Falling back to scanning...\n" if $error;
|
135
|
-
|
136
|
-
# Uncomment for debugging watchman output
|
137
|
-
# open (my $fh, ">", ".git/watchman-output.out");
|
138
|
-
# close $fh;
|
139
|
-
|
140
|
-
# Watchman will always return all files on the first query so
|
141
|
-
# return the fast "everything is dirty" flag to git and do the
|
142
|
-
# Watchman query just to get it over with now so we won't pay
|
143
|
-
# the cost in git to look up each individual file.
|
144
|
-
my $o = watchman_clock();
|
145
|
-
$error = $output->{error};
|
146
|
-
|
147
|
-
die "Watchman: $error.\n" .
|
148
|
-
"Falling back to scanning...\n" if $error;
|
149
|
-
|
150
|
-
output_result($o->{clock}, ("/"));
|
151
|
-
$last_update_token = $o->{clock};
|
152
|
-
|
153
|
-
eval { launch_watchman() };
|
154
|
-
return 0;
|
155
|
-
}
|
156
|
-
|
157
|
-
die "Watchman: $error.\n" .
|
158
|
-
"Falling back to scanning...\n" if $error;
|
159
|
-
|
160
|
-
return 1;
|
161
|
-
}
|
162
|
-
|
163
|
-
sub get_working_dir {
|
164
|
-
my $working_dir;
|
165
|
-
if ($^O =~ 'msys' || $^O =~ 'cygwin') {
|
166
|
-
$working_dir = Win32::GetCwd();
|
167
|
-
$working_dir =~ tr/\\/\//;
|
168
|
-
} else {
|
169
|
-
require Cwd;
|
170
|
-
$working_dir = Cwd::cwd();
|
171
|
-
}
|
172
|
-
|
173
|
-
return $working_dir;
|
174
|
-
}
|
.git/hooks/post-update.sample
DELETED
.git/hooks/pre-applypatch.sample
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
#!/bin/sh
|
2
|
-
#
|
3
|
-
# An example hook script to verify what is about to be committed
|
4
|
-
# by applypatch from an e-mail message.
|
5
|
-
#
|
6
|
-
# The hook should exit with non-zero status after issuing an
|
7
|
-
# appropriate message if it wants to stop the commit.
|
8
|
-
#
|
9
|
-
# To enable this hook, rename this file to "pre-applypatch".
|
10
|
-
|
11
|
-
. git-sh-setup
|
12
|
-
precommit="$(git rev-parse --git-path hooks/pre-commit)"
|
13
|
-
test -x "$precommit" && exec "$precommit" ${1+"$@"}
|
14
|
-
:
|