kowainik / hintman Goto Github PK
View Code? Open in Web Editor NEW๐ซ GitHub application to suggest hints
Home Page: https://github.com/apps/hint-man
License: Mozilla Public License 2.0
๐ซ GitHub application to suggest hints
Home Page: https://github.com/apps/hint-man
License: Mozilla Public License 2.0
Using hlint
as library and data types from there.
Here is the documentation:
In HLint the Idea
stores the SrcLoc
of the corresponding code of the hint, so we should make sure that we make the suggestion only to the corresponding part and leave the rest as it is.
GitHub tutorial briefly mentions to use Heroku.
Basically, just implement simple endpoint that will print some info about open PRs for the repo. We're going to use the following libraries:
And here is the simple example of using servant-github-webhook
:
Looks like InstallationToken
is shared for all repositories of the same user. So we can simplify mapping and make code more correct.
So, since we now have multiple hints, it actually makes sense to think about aggregating structure. So the overal structure is the following:
suggest :: [(FilePath, Text)] -> [Suggestion]
It takes path to file and content of this file and performs joinSuggestions . concatMap suggestSingle
where
2. The function suggestSingle
will split incoming text over lines and then run all our suggestions either on every line or on the whole content
3. We might have multiple suggestions for single line so we need to aggregate suggestions. For example, if we have trailing line \n
we need to perform the only suggestion that removes this line, not two suggestions. So should Suggestion
type be Monoid
๐ค Any ideas are appreciated!
I don't know why it's needed but Ruby example has it.
We need to verify that requests are from GitHub. But for now we can just print all incoming requests and see what they contain.
So later we can enable or disable logging in our application via this flag.
Blocked by #10
Currently just do putTextLn
. Later we will use co-log
for logging ๐
Some may want to see all hints and warnings, some may not.
We should filter on this data type then: Severity
Function with roughly with the following type (of course, we should use data types instead of tuples):
suggestNoTrailingSpaces :: (FilePath, Text) -> Maybe (FilePath, LineNumber, Text)
which generates suggestion comment for github with the same line but without trailing spaces if the line has one.
Module: Hintman.Suggest
And then implement function that takes list of files with lines and diffs and traverses all lines and generate all hints.
We need to think about how to generate random data with trailing spaces, implement verification function for this data and then check against the function implemented in #3
Documentation for building APP:
I would like to have instructions how to configure environment before running application. Better in a form of shell script. So in terminal everyone can just:
$ ./setup-app-env.sh
$ cabal new-exec hintman # or `stack exec hintman`
If something is required to do manually, this should be specified in the README.md file.
We can submit suggestions only to changed lines. We get this information from diff-parse
. So we need to filter all hints according to diff.
There's problem that requestBody
is deprecated and getBodyChunks
consumes request body making it not accessible to further. This problem should be solved after GSoC project for servant-auth
when this library becomes extensible.
Let's not remove authentication completely. Just comment all code that verifies signatures (and remove cryptonite
from dependencies) and just log incoming request in there.
This might be a useful thing to add to the context along with whether or not to log things.
Currently we print all request to the terminal. But we need to implement verification. See these lines from boilerplate app:
HintmanAppM
to just App
HintmanEnv
to just Env
App
to Hintman.App.Monad
Env
to Hintman.App.Env
Can be started after #38
Can be started after #38
ReaderT Env IO
representation is more efficient.
Just check how it's done in summoner
Currently hintman
doesn't start when config file is not present. I think it's better to use default configuration in that case and print that it will be used.
We now have multiple checks. And it's probably a good idea to have a config for our tool anyways. So we can create Config
data type where we can store all checks and allow users to have .hintman.toml
in their repos to disable or enable checks.
Should go in Hintman.Config
module.
We need to cache installation Id for each pair of owner and repo. And we also should keep tokens for 1 hour and reuse them without renewal.
Basically, implement simple API with servant
that returns number 42
on some predefined URL like
/api/the-answer
We should use generic servant for that.
The module name can be Hintman.Server
.
Blocked by #39
Similar to #3 but should check that commit introduces trailing newlines.
Might be a bit hard but for every file we should check that diff lines at the end of this file doesn't introduce trailing newlines.
Let's do this in separate module Hintman.Suggest.TrailingNewline
(probably later will be merged with what @willbasky is doing).
When the PR is open, we need to get all files, their content and run hlint
over them. We're going to use hlint
as a library.
This function should do the following:
InstallationToken
from the contextThere's Context
in servant
and having Context
for CLI makes this a little bit awkward...
This could even be couple of unit tests with hspec
I'm not sure how it's going to work. But if we deploy GitHub app manually as a runnable server, we have to figure out how to persist installation ids to be able to restart server smoothly. If we store them only in memory we lose all information and can't run hintman
over repos where it's already installed.
When PR is open, hintman
should create some dummy comment on the diff. The API is tricky but dummy comment should be easy to create:
It's possible to specify only some repositories via GitHub API to be accessible by Hintman. So there are two options:
servant
optparse-applicative
jwt
hedgehog
relude
tomland
curl
command:
curl -i -H "Accept: application/vnd.github.v3.diff" https://api.github.com/repos/gr2m/sandbox/pulls/7
And here is the library we're going to use for parsing diffs:
Some repositories may have their own .hlint.yaml
files. It would be nice to support them.
So everyone can test GitHub application. Here is the application:
It's created under my account but probably we need to create one under Kowainik. And also we probably need to create one more GitHub application for testing...
Also, probably we need to create an empty repository for testing. But this repository can be useful for both hintman
and hit
.
According to our latest innovations
This is a final issue. Basically, wire up everything together. This is a tricky issue, we need to figure out how to use GitHub API to submit comments for corresponding lines....
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.