Skip to content

Commit 1e7b532

Browse files
committed
Initial commit
0 parents  commit 1e7b532

83 files changed

Lines changed: 937 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/pr-checks.yml

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
name: PR Checks
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize]
6+
branches:
7+
- main
8+
9+
jobs:
10+
get-changed-files:
11+
runs-on: ubuntu-latest
12+
outputs:
13+
tasks: ${{ steps.changed.outputs.tasks }}
14+
tests: ${{ steps.changed.outputs.tests }}
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v4
18+
with:
19+
fetch-depth: 0
20+
21+
- name: Get changed Python files
22+
id: changed
23+
run: |
24+
files=$(git diff --name-only HEAD~1)
25+
echo "Changed files:"
26+
echo "$files"
27+
28+
tasks=$(echo "$files" | grep 'python/tasks/.*\.py$' | paste -sd " ")
29+
echo "Changed tasks:"
30+
echo "$tasks"
31+
echo "tasks=$tasks" >> $GITHUB_OUTPUT
32+
33+
tests=$(echo "$files" | grep 'python/tasks/.*\.py$' | sed 's|tasks/task|test|' | paste -sd " ")
34+
echo "Corresponding tests:"
35+
echo "$tests"
36+
echo "tests=$tests" >> $GITHUB_OUTPUT
37+
38+
autopep8:
39+
needs: get-changed-files
40+
runs-on: ubuntu-latest
41+
if: needs.get-changed-files.outputs.tasks != ''
42+
steps:
43+
- name: Checkout code
44+
uses: actions/checkout@v4
45+
46+
- name: Set up Python
47+
uses: actions/setup-python@v5
48+
with:
49+
python-version: '3.13'
50+
51+
- name: Install autopep8
52+
run: |
53+
python -m pip install --upgrade pip
54+
pip install autopep8
55+
56+
- name: Run autopep8 on changed files
57+
run: |
58+
autopep8 --max-line-length 120 --exit-code --diff ${{ needs.get-changed-files.outputs.tasks }}
59+
60+
pytest:
61+
needs: get-changed-files
62+
runs-on: ubuntu-latest
63+
if: needs.get-changed-files.outputs.tests != ''
64+
steps:
65+
- name: Checkout code
66+
uses: actions/checkout@v4
67+
68+
- name: Set up Python
69+
uses: actions/setup-python@v5
70+
with:
71+
python-version: '3.13'
72+
73+
- name: Install dependencies
74+
run: |
75+
python -m pip install --upgrade pip
76+
pip install pytest
77+
78+
- name: Run pytest for changed files
79+
run: |
80+
pytest ${{ needs.get-changed-files.outputs.tests }}

CODEOWNERS

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# This is a comment.
2+
# Each line is a file pattern followed by one or more owners.
3+
4+
# These owners will be the default owners for everything in
5+
# the repo. Unless a later match takes precedence,
6+
# @global-owner1 and @global-owner2 will be requested for
7+
# review when someone opens a pull request.
8+
#* @global-owner1 @global-owner2
9+
* @ZelenyMartin @ejegrova

README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# GitHub a pull requesty
2+
3+
Práce s tímto repozitářem bude simulovat **skutečný způsob práce na GitHubu**, kdy budete chtít dosáhnout umístění svého kódu v branchi _main_ v hlavním repu.
4+
5+
Zatím jsou zde úkoly na Python, ale možná přibudou i skriptovací úkoly pro Bash. ChatGPT mi vytvořilo podle zadání bashový skript, který vygeneroval všechny tasky i unit testy. Musel jsem to trochu upravit, protože to nefungovalo hned out-of-the-box. Příkaz `pytest` spustí všechny testy.
6+
7+
Funkce s tasky používají _typing annotation_ - je to moderní způsob psaní funkcí v Pythonu, kdy určujeme datové typy parametrů funkce a datový typ návratové hodnoty.
8+
9+
Úkoly 01 až 25 jsou jednoduché. Výzvou jsou až úkoly 25 až 40.
10+
11+
### Postup samostatné práce
12+
13+
1. Nahlásíš svůj GitHub username, abychom ti dali právo zápisu do tohoto repa
14+
1. Vybereš si na jakém tasku budeš dělat. V tomto repozitáři na GitHubu založíš **Isssue** s title číslo úkolu (např. **01**) - tím si úkol _zarezervuješ_, aby nikdo jiný neposlal pull request se svým řešením dřív než ty.
15+
1. Vyřešíš a otestuješ task
16+
* Spustíš na své řešení `autopep8` - přečti si o [Coding style](https://kodim.cz/czechitas/uvod-do-progr-2/bonusy/coding-style/coding-style)
17+
* Spustíš na své řešení `pytest`
18+
* Jednotlivý test spustíš:
19+
```
20+
pytest test_01_sum_two_numbers.py -vv
21+
```
22+
23+
Parametr `-v` a `-vv` zvyšuje vypisování detailů chyb.
24+
25+
1. Commitneš řešení do nové branche
26+
* Název branche **musí obsahovat tvoje jméno nebo iniciály, číslo tasku** a krátký popisek:
27+
* `mz-01-sum-two-numbers`
28+
* **Commit message musí začínat číslem tasku** a pokračovat vhodným popiskem:
29+
* `01 Soucet dvou cisel`
30+
* Pushneš tuto branch do tohoto repa.
31+
1. Vytvoříš PR, které bude chtít zamergovat branch s řešením tasku do branche main.
32+
* **PR musí obsahovat přesně jeden tvůj commit**
33+
* Nech si od koučů poradit s `git commit --amend` popř. `git rebase -i`.
34+
* Aby byla hra na práci co nejvěrnější, je v repozitáři nastaveno CI (Continuous integration)
35+
* GitHub Action automaticky spustí `autopep8` a `pytest` pro tvůj task
36+
* Toto GitHub Action [workflow](.github/workflows/pr-checks.yml) bylo také vygenerováno pomocí ChatGPT, ale bylo opět nutné ho rozfungovat a zlepšit.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# task_01_sum_two_numbers.py
2+
3+
def sum_two_numbers(a: int, b: int) -> int:
4+
"""
5+
Vrátí součet dvou čísel.
6+
"""
7+

python/tasks/task_02_is_even.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# task_02_is_even.py
2+
3+
def is_even(n: int) -> bool:
4+
"""
5+
Vrátí True, pokud je číslo sudé.
6+
"""
7+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# task_03_max_of_three.py
2+
3+
def max_of_three(a: int, b: int, c: int) -> int:
4+
"""
5+
Vrátí největší ze tří čísel.
6+
"""
7+

python/tasks/task_04_factorial.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# task_04_factorial.py
2+
3+
def factorial(n: int) -> int:
4+
"""
5+
Vrátí faktoriál čísla n.
6+
"""
7+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# task_05_count_vowels.py
2+
3+
def count_vowels(s: str) -> int:
4+
"""
5+
Vrátí počet samohlásek v řetězci.
6+
"""
7+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# task_06_filter_by_age.py
2+
3+
def filter_by_age(people: dict):
4+
"""
5+
Napiš funkci filter_by_age, která vezme seznam slovníků, kde každý slovník
6+
představuje osobu (s klíči name a age), a vrátí seznam osob, které jsou
7+
starší než 18 let.
8+
"""
9+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# task_07_reverse_string.py
2+
3+
def reverse_string(s: str) -> str:
4+
"""
5+
Vrátí obrácený řetězec.
6+
"""
7+

0 commit comments

Comments
 (0)