DEV Community

ShulyAvraham
ShulyAvraham

Posted on • Updated on

OSDC LESSON 8: Webhooks, git stash, tests coverage report

GitHub

Webhooks

Found on the left bar on github website.

Define an event (e.g. push) that triggers a call to a website that I created. The event will call the website and send a json file with information from github. Then this website will receive the json file from github and perform things e.g. git pull and then generate pages from the files...

git stash

Take the local changes, keep them aside, and return to the latest committed version.

git stash
Enter fullscreen mode Exit fullscreen mode

The changes were not lost.

Now I can

git pull
Enter fullscreen mode Exit fullscreen mode

Bring my changes back from stash to my working directory.

git stash pop
Enter fullscreen mode Exit fullscreen mode

The stash is a stack that keeps several changes. To see all changes:

git stash list
Enter fullscreen mode Exit fullscreen mode

To see the most recent change in the stash

git stash show -p
Enter fullscreen mode Exit fullscreen mode

To see a change in a specific stash in the stack

git stash show 1
Enter fullscreen mode Exit fullscreen mode

Remove the most recent change from stash

git stash drop
Enter fullscreen mode Exit fullscreen mode

Remove a specific change from the stash

git stash drop 1
Enter fullscreen mode Exit fullscreen mode

Stash pop might also cause a merge conflict which needs to be resolved. In that case, the change will not be removed from the stash.

Docker playground

https://github.com/szabgab/playground

We can use @szabgab docker as playground

alias dr='docker run -it --rm --workdir /opt -v$(pwd):/opt szabgab/playground:latest bash'
dr
Enter fullscreen mode Exit fullscreen mode
dr
Enter fullscreen mode Exit fullscreen mode

Run an image

docker run imagename:version
Enter fullscreen mode Exit fullscreen mode

If the image does not exist locally it will be downbloaded first from docker hub and then run.

Build a docker from a Docker file

docker build -t username/dockername:version
Enter fullscreen mode Exit fullscreen mode

Run a project from git inside docker

Use @szabgab playground docker

dr
Enter fullscreen mode Exit fullscreen mode

Or use some other docker image

docker run -it --rm --workdir /opt -v$(pwd):/opt python:3.11 bash
Enter fullscreen mode Exit fullscreen mode

To explore the project we can look at the github folder, and we might find the ci tests.

make and Makefile

Run shell commands with dependencies
Instead of README.md - the Makefile contains all the commands to be run, and executing make will run these commands.
make is the command and Makefile is a file that contains commands. Each set of commands have some tag. So one might run the specific set of commands in a tag

make sometag
Enter fullscreen mode Exit fullscreen mode

Example for the Makefile

init:
    pip install -r requirements.txt
ci:
    pytest tests

Enter fullscreen mode Exit fullscreen mode

So to run the ci

make ci
Enter fullscreen mode Exit fullscreen mode

tox

a tool to run tests on several versions of python

Coverage report for tests

First install

pip install pytest pytest-random-order pytest-coverage
Enter fullscreen mode Exit fullscreen mode
pytest -svv --random-order --cov-branch cov-report html cov-report  term cov somedir......
Enter fullscreen mode Exit fullscreen mode

random-order runs functions on random order to make sure functions are not dependent on each other

cov-report html will generate the report in html format

cov-report term will send the report to the terminal

cov-branch Branch coverage
In case we have an if command in the code, or loop or something along these lines, it means that depending on the data transferred to the function the code inside the if or loop might be executed or not. So the cov-branch will report in case we have several "branches" in the code, and the coverage for all branches.

contribute to pydigger

  • Look at the list of missing stuff.
  • Pick a project.
  • Go to the github of the project.
  • make a change on the project's github (e.g. add the author to the setup.py file)
  • Send a pull request
  • Once the author of the project accepts the change and place it on pypi, pydigger will retrieve the change and be updated accordingly.

Top comments (0)