Skip to content

Conversation

@jmeridth
Copy link
Member

@jmeridth jmeridth commented Mar 12, 2024

Pull Request

Proposed Changes

  • add github app env variables to env.py and test
  • setup requirements-test.txt for local testing
    • change python-ci workflows to use new requirements-test.txt file
  • add all possible env vars to .env-example, group and alphabetize
  • purposefully clear out env vars before each env var test, just in case developer loaded .env into local shell manually (like I did)
  • add flag to get_env_vars method to determine when to load .env file
  • Update README with example and variable information

Readiness Checklist

Author/Contributor

  • If documentation is needed for this change, has that been included in this pull request
  • run make lint and fix any issues that you have introduced
  • run make test and ensure you have test coverage for the lines you are introducing

Local Testing and Linting

Testing

➜  make test
pytest -v --cov=. --cov-config=.coveragerc --cov-fail-under=80 --cov-report term-missing
====================================================== test session starts =======================================================
platform darwin -- Python 3.11.8, pytest-8.1.1, pluggy-1.4.0 -- /Users/jmeridth/code/cleanowners/.venv/bin/python3.11
cachedir: .pytest_cache
rootdir: /Users/jmeridth/code/cleanowners
plugins: cov-4.1.0
collected 15 items

test_auth.py::TestAuth::test_auth_to_github_with_ghe PASSED                                                                [  6%]
test_auth.py::TestAuth::test_auth_to_github_with_github_app PASSED                                                         [ 13%]
test_auth.py::TestAuth::test_auth_to_github_with_token PASSED                                                              [ 20%]
test_auth.py::TestAuth::test_auth_to_github_without_token PASSED                                                           [ 26%]
test_cleanowners.py::TestCommitChanges::test_commit_changes PASSED                                                         [ 33%]
test_cleanowners.py::TestGetUsernamesFromCodeowners::test_get_usernames_from_codeowners PASSED                             [ 40%]
test_cleanowners.py::TestGetReposIterator::test_get_repos_iterator_with_organization PASSED                                [ 46%]
test_cleanowners.py::TestGetReposIterator::test_get_repos_iterator_with_repository_list PASSED                             [ 53%]
test_env.py::TestEnv::test_get_env_vars_missing_org_or_repo PASSED                                                         [ 60%]
test_env.py::TestEnv::test_get_env_vars_missing_token PASSED                                                               [ 66%]
test_env.py::TestEnv::test_get_env_vars_optional_values PASSED                                                             [ 73%]
test_env.py::TestEnv::test_get_env_vars_with_github_app_and_repos PASSED                                                   [ 80%]
test_env.py::TestEnv::test_get_env_vars_with_org PASSED                                                                    [ 86%]
test_env.py::TestEnv::test_get_env_vars_with_repos_no_dry_run PASSED                                                       [ 93%]
test_env.py::TestEnv::test_get_env_vars_with_token_and_repos PASSED                                                        [100%]

---------- coverage: platform darwin, python 3.11.8-final-0 ----------
Name             Stmts   Miss  Cover   Missing
----------------------------------------------
auth.py             14      1    93%   41
cleanowners.py      36      0   100%
env.py              60     10    83%   25-26, 68-69, 80, 96, 122, 131, 141, 150
----------------------------------------------
TOTAL              110     11    90%

Required test coverage of 80% reached. Total coverage: 90.00%

Linting

➜  make lint
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics --exclude=venv,.venv,.git,__pycache__
0
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=100 --max-line-length=150 --statistics --exclude=venv,.venv,.git,__pycache__
0
pylint --rcfile=.pylintrc --fail-under=9.0 *.py

Reviewer

  • Label as either bug, documentation, enhancement, infrastructure, or breaking

@jmeridth jmeridth requested a review from zkoppert as a code owner March 12, 2024 09:50
@jmeridth jmeridth force-pushed the jm-github-app-auth branch 2 times, most recently from 5a7acc9 to 843507b Compare March 12, 2024 09:52
@jmeridth
Copy link
Member Author

Unable to test superlinter locally due to super-linter/super-linter#5320. I'm watching that PR. So I will push fixes if any issues superlinter GitHub Action finds 😄

@jmeridth jmeridth changed the title chore: allow github app authentication feat: allow github app authentication Mar 12, 2024
@jmeridth jmeridth marked this pull request as draft March 12, 2024 17:08
- [x] add github app env variables to env.py and test
- [x] setup requirements-test.txt for local testing
  - [x] change python-ci workflows to use new requirements-test.txt file
- [x] add all possible env vars to .env-example, group and alphabetize
- [x] purposefully clear out env vars before each env var test, just
  in case developer loaded .env into local shell manually (like I did)
- [x] add flag to get_env_vars method to determine when to load .env
  file
- [x] Update README with example and variable information

Signed-off-by: jmeridth <jmeridth@gmail.com>
@jmeridth jmeridth force-pushed the jm-github-app-auth branch from 843507b to 014b544 Compare March 12, 2024 17:21
@jmeridth jmeridth marked this pull request as ready for review March 12, 2024 17:21
@zkoppert zkoppert added the enhancement New feature or request label Mar 12, 2024
@jmeridth
Copy link
Member Author

jmeridth commented Mar 12, 2024

Working through the linting errors. Handled most linting errors. Wondering if those fix the last 3 I was seeing. Had to change the type of the token as os.getenv returns either a string or None (str | None).

jmeridth and others added 5 commits March 12, 2024 13:34
Signed-off-by: jmeridth <jmeridth@gmail.com>
Signed-off-by: Zack Koppert <zkoppert@github.com>
when using os.getenv it can return string or None.  Changed
token variable to be same type (str | None)

Signed-off-by: jmeridth <jmeridth@gmail.com>
Signed-off-by: Zack Koppert <zkoppert@github.com>
@jmeridth
Copy link
Member Author

Going to run black formatter locally before open PRs. Thanks @zkoppert for handling.

@zkoppert
Copy link
Member

Taking a deeper look at this today!

jmeridth and others added 5 commits March 14, 2024 16:03
Co-authored-by: Zack Koppert <zkoppert@github.com>
Co-authored-by: Zack Koppert <zkoppert@github.com>
Co-authored-by: Zack Koppert <zkoppert@github.com>
Co-authored-by: Zack Koppert <zkoppert@github.com>
Co-authored-by: Zack Koppert <zkoppert@github.com>
@jmeridth
Copy link
Member Author

Clearer documentation ftw. Thank you @zkoppert

Signed-off-by: Zack Koppert <zkoppert@github.com>
Copy link
Member

@zkoppert zkoppert left a comment

Choose a reason for hiding this comment

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

@zkoppert zkoppert merged commit f7ee4d1 into github:main Mar 14, 2024
@jmeridth jmeridth deleted the jm-github-app-auth branch March 15, 2024 16:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants