Skip to content
This repository was archived by the owner on Sep 22, 2021. It is now read-only.

Automate Code Review and Merge #32

Closed
yogeshsingh01 opened this issue Sep 20, 2020 · 21 comments · Fixed by #731
Closed

Automate Code Review and Merge #32

yogeshsingh01 opened this issue Sep 20, 2020 · 21 comments · Fixed by #731
Assignees
Labels
hacktoberfest help wanted Extra attention is needed

Comments

@yogeshsingh01
Copy link
Contributor

yogeshsingh01 commented Sep 20, 2020

Code Review

Code Review should be automated
It is an enhancement

Expected behaviour

If someone request a pull request, bot will automatically check solution on LeetCode, if it work fine then it should merge.

@vJechsmayr vJechsmayr added hacktoberfest help wanted Extra attention is needed labels Sep 23, 2020
@sadn1ck
Copy link
Contributor

sadn1ck commented Sep 25, 2020

This looks interesting. I'd like to work on this.

I have never really done this thing before, so what do you recommend?

Based on my minimal research, I assume I can use https://github.com/skygragon/leetcode-cli in a CI build somewhere. EDIT: On further looking, this requires a login.

Though I think a manual check should be there before merging.

@yogeshsingh01
Copy link
Contributor Author

@sadn1ck I assume that should work.
As travis(CI) is not setup for this project. We should do that first.

@vJechsmayr Whats your take?

@vJechsmayr
Copy link
Owner

@sadn1ck @yogeshsingh01 Please go ahead - about Automation or Travis CI I have no idea about it.

Maybe @sadn1ck Is right and we should manual check before merging - but we can precheck and maybe comment if the Check on Leetcode was successful?! ("LeetCode Check Success - LeetCode Check Failed")

@sadn1ck
Copy link
Contributor

sadn1ck commented Oct 1, 2020

I have a suggestion: we could have a staging branch where all pull requests are merged, and checked for correctness with the CLI in a GitHub workflow or travisCI pipeline.

If any fail, we can reopen the issue, and have contributors work on it.

After that, we can just have the staging branch merge into master every week or so, when every question passes.
(Need to make sure we know at which problem build fails as well heh)

@yogeshsingh01 @vJechsmayr Thoughts?

@vJechsmayr
Copy link
Owner

@sadn1ck I think the idea with the staging branch is great - For the merging staging to master it's important that only correct solutions (also with correct File-Names) passes the tests.

@yogeshsingh01
Copy link
Contributor Author

@sadn1ck As leetcode has changed its policy, previously one can login via a config file.
Now login is only possible via cookies.

Hence, you can give Terminal LeetCode a try.

To be precise, one have to implement something like this:
LeetCode-Sync

In this they are syncing your leetcode progress, What we are focusing is just a part of that.
You can use code snippet from leetcode-sync

Let me know if anything is not clear or if you need any help.

@sadn1ck
Copy link
Contributor

sadn1ck commented Oct 3, 2020

I'll have a look, ty @yogeshsingh01 , swamped in college work right now. 😅

@sadn1ck
Copy link
Contributor

sadn1ck commented Oct 6, 2020

Hey, so I had a look at https://github.com/joshcai/leetcode-sync, so what I understood was that I have to send a request with the code to /problems/problem-name/submit, with the question id, language and code. (along with the CSRF Token and the leetcode session token)

image

The previous endpoint doesn't actually return if it's accepted or not, so we have to make another request to /submissionid/check like it's done here.

image

So, the basic workflow would be something like this,

  • Get the file changed in PR
  • Parse question id, and question name (name is a problem, might need to change to actual name used in the URL by leetcode) from file name, and the code from the contents of the file
  • Send a request to the /submission endpoint
  • Wait 1 second, and send a request to the /submissionid/check endpoint to see if it is sucessful
  • If successful, pass PR checks, if not, fail PR checks

The question right now I have is, how do I get the file which was added in the PR? And how do I create the check thingy?

@yogeshsingh01
Copy link
Contributor Author

yogeshsingh01 commented Oct 6, 2020 via email

@vJechsmayr
Copy link
Owner

@sadn1ck Wow thats great, Maybe we can find some answers in the github or github-actions API/FAQ how to access to the PR-File?

@sadn1ck
Copy link
Contributor

sadn1ck commented Oct 6, 2020

@vJechsmayr Yeah I am currently scouring the docs, if I find something I will let you know. If you find something, do let me know as well.

Also, do we have a gitter or a communication app of some sort? It would simplify collaboration, is all. 😅

@yogeshsingh01
Copy link
Contributor Author

yogeshsingh01 commented Oct 6, 2020 via email

@sadn1ck
Copy link
Contributor

sadn1ck commented Oct 6, 2020

Great! I'll start on it as soon as I can.

@vJechsmayr
Copy link
Owner

I tested the LeetCode Sync Action on my other Repo - to see how it works: It syncs the submitted Problems FROM LeetCode TO Github - not the other way 😢
@sadn1ck Have you found something the other way? From Github to LeetCode?

I'm back in 9h - go to work now 😸

@vJechsmayr
Copy link
Owner

I'm almost new to gitter Gitter (just used it 2-3 times) to I hope that community I created will help? I'm open for suggestions 😸

@sadn1ck
Copy link
Contributor

sadn1ck commented Oct 6, 2020

Yeah I just looked at the repo for the how the requests are sent (the params and endpoints).

Here, I will write a script which uses that, and which runs in the workflow, and sends some API calls to leetcode.

Hoping the script method will work haha.

@sadn1ck
Copy link
Contributor

sadn1ck commented Oct 7, 2020

https://github.com/sadn1ck/PythonAlgorithms/commit/8ff18feb561183a69a7ac78a378d22970c86b76f

I have made a commit, with the base of the script setup, I am able to craft the request, but on POSTing, I get a 500 server error. :|

(for testing locally, just set the sample.env values)

@yogeshsingh01
Copy link
Contributor Author

I am unable to understand, what is error. Could you provide some more information. @sadn1ck

@sadn1ck
Copy link
Contributor

sadn1ck commented Oct 7, 2020

image

So basically I made the request how it happens when you click submit in leetcode, but I get an internal server error when I actually make the request. Sometimes I get 429, and sometimes 500 status codes. @yogeshsingh01

You can join the gitter above, easier to talk 😃 Gitter Link

@yogeshsingh01
Copy link
Contributor Author

@vJechsmayr @sadn1ck Bot is working perfectly.
Check yogeshsingh01#14
Let me know how you want to proceed

@sadn1ck
Copy link
Contributor

sadn1ck commented Oct 11, 2020

Great!!! Nice one @yogeshsingh01 !!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
hacktoberfest help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants