Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #5938: Lint checks will run only for the files changed by the user #6033

Merged
merged 20 commits into from
Jan 3, 2019

Conversation

lilithxxx
Copy link
Contributor

@lilithxxx lilithxxx commented Dec 27, 2018

Fixes #5938

Explanation

Previously the pre_push_hook tested against the remote branch of our local repository (i.e local_repo:develop) but now is changed to test against the remote branch of Oppia's repository (i.e oppia:develop). This will prevent the linter to check the files touched by a foreign commit.

This requires user to have their upstream set.

Checklist

  • The PR title starts with "Fix #bugnum: ", followed by a short, clear summary of the changes. (If this PR fixes part of an issue, prefix the title with "Fix part of #bugnum: ...".)
  • The PR explanation includes the words "Fixes #bugnum: ..." (or "Fixes part of #bugnum" if the PR only partially fixes an issue).
  • The linter/Karma presubmit checks have passed.
    • These should run automatically, but if not, you can manually trigger them locally using python scripts/pre_commit_linter.py and bash scripts/run_frontend_tests.sh.
  • The PR is made from a branch that's not called "develop".
  • The PR follows the style guide.
  • The PR is assigned to an appropriate reviewer.
    • If you're a new contributor, please ask on Gitter for someone to assign a reviewer.
    • If you're not sure who the appropriate reviewer is, please assign to the issue's "owner" -- see the "talk-to" label on the issue.

@codecov-io
Copy link

codecov-io commented Dec 27, 2018

Codecov Report

Merging #6033 into develop will decrease coverage by 0.05%.
The diff coverage is n/a.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #6033      +/-   ##
===========================================
- Coverage    45.27%   45.21%   -0.06%     
===========================================
  Files          521      523       +2     
  Lines        30688    30722      +34     
  Branches      4597     4605       +8     
===========================================
- Hits         13894    13892       -2     
- Misses       16794    16830      +36
Impacted Files Coverage Δ
...dev/head/pages/exploration_editor/RouterService.js 17.5% <0%> (-5.31%) ⬇️
...head/pages/exploration_editor/ExplorationEditor.js 5.12% <0%> (-0.11%) ⬇️
...es/exploration_editor/EditorNavigationDirective.js 2.08% <0%> (-0.1%) ⬇️
...ges/exploration_editor/settings_tab/SettingsTab.js 0.62% <0%> (ø) ⬆️
...ad/pages/skill_editor/SkillEditorRoutingService.js 4% <0%> (ø) ⬆️
...s/exploration_editor/ExplorationWarningsService.js 11.34% <0%> (ø) ⬆️
...loration_editor/EditorNavbarBreadcrumbDirective.js 5.55% <0%> (ø) ⬆️
...ad/pages/topic_editor/TopicEditorRoutingService.js 3.33% <0%> (ø) ⬆️
...ditor/CollectionEditorNavbarBreadcrumbDirective.js 9.09% <0%> (ø) ⬆️
...r/editor_tab/UnresolvedAnswersOverviewDirective.js 1.13% <0%> (ø) ⬆️
... and 6 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 59260be...8bb2609. Read the comment docs.

if [ ! -d "$TOOLS_DIR/GitPython" ]; then
echo Installing GitPython

pip install gitpython --target="$TOOLS_DIR/GitPython"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of points here:

  1. Can we fix the version of gitpython we use here?
  2. Can we use curl instead of pip?

Also, the tests seem to be failing on Travis due to import error (see here).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@apb7
Copy link
Contributor

apb7 commented Dec 30, 2018

@lilithxxx, the import error in the tests is due to the fact that git module has not been added to system paths. See around this line on how to insert the required path: https://github.com/oppia/oppia/blob/develop/scripts/pre_commit_linter.py#L273

@lilithxxx
Copy link
Contributor Author

Hi @apb7 I changed the code to use subprocess instead of gitpython. PTAL

Copy link
Contributor

@apb7 apb7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @lilithxxx, I think using GitPython would be quite better than using subprocess -- it will streamline the workflow here. Thanks!

@apb7 apb7 assigned lilithxxx and unassigned apb7 Jan 1, 2019
@lilithxxx
Copy link
Contributor Author

@apb7 Made some changes. PTAL

@apb7
Copy link
Contributor

apb7 commented Jan 2, 2019

@lilithxxx, there are still import errors for the package. ptal! Thanks.

@apb7
Copy link
Contributor

apb7 commented Jan 2, 2019

@lilithxxx, I looked into the import error with GitPython. This SO post is useful here -- you need gitdb and smmap as well in the path. Also, I think that adding the paths to these modules in pre_commit_linter.py itself will be sufficient.

@@ -148,6 +148,24 @@ if [ ! -d "$TOOLS_DIR/isort-4.2.15" ]; then
rm isort-4.2.15.tar.gz
fi

# Install GitPython and its dependencies.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of points here -- make this as three separate echos instead of one Installing GitPython and its dependencies so that even if any one of them is already installed, we skip that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -292,6 +292,9 @@
os.path.join(_PARENT_DIR, 'oppia_tools', 'pylint-quotes-0.1.9'),
os.path.join(_PARENT_DIR, 'oppia_tools', 'selenium-2.53.2'),
os.path.join(_PARENT_DIR, 'oppia_tools', 'PIL-1.1.7'),
os.path.join(_PARENT_DIR, 'oppia_tools', 'GitPython-2.1.11'),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Place smmap first then gitdb and then GitPython (in the order of the dependence relation).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not done?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So sorry -- done now


# Add GitPython to sys.path, then only it can be imported.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change this to Insert GitPython to sys.path so that it can be imported.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

remote_num += 1
remote_name = remote.name

if remote_num == 0:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can remove the equality check, 0 will evaluate to false.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand this -- We are checking if there is an upstream set or not. Can you please come again? Thanks

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad, make it if not remote_num.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

for branch, sha1, remote_sha1 in zip(branches, hashes, remote_hashes):
# Git reports the following for an empty / non existing branch
# sha1: '0000000000000000000000000000000000000000'.
if set(remote_sha1) != {'0'}:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't we require this part, that is, the removed portion of the code now?

Copy link
Contributor Author

@lilithxxx lilithxxx Jan 2, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here it was comparing the changes of the local branch with the local branch itself if the branch is not empty and compared with origin if the branch was empty(i.e had no changes in it)
Now, we are making it compare to upstream at all time.

@lilithxxx
Copy link
Contributor Author

@apb7 Made the changes. PTAL

@@ -94,6 +103,33 @@ def _start_subprocess_for_result(cmd):
return out, err


def _get_remote_name():
"""Get the remote name of the local repository.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you're missing a new line here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


# Insert GitPython to sys.path so that it can be imported.
_PARENT_DIR = os.path.abspath(os.path.join(os.getcwd(), os.pardir))
GIT_PYTHON_PATH = os.path.join(_PARENT_DIR, 'oppia_tools', 'GitPython-2.1.11')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lilithxxx, the build is failing due to import error. I think you'll have to add paths to both the dependencies here as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Contributor

@apb7 apb7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks @lilithxxx! Tested it by pulling this branch and making several merge commits -- the functionality seems to be working as expected.

@apb7
Copy link
Contributor

apb7 commented Jan 3, 2019

@nithusha21, if you're around, can you please give this a try before we merge this? Thanks!

@apb7 apb7 assigned nithusha21 and unassigned lilithxxx Jan 3, 2019
@nithusha21
Copy link
Contributor

Tested locally, seems to be working fine! Thanks for the fix @lilithxxx :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Only lint files changed by the local user and not by foreign commits
4 participants