Commit 452b5b3e authored by Tomas Tomecek's avatar Tomas Tomecek
Browse files

add initial HW check script

parent 41c6d3a1
Loading
Loading
Loading
Loading
+31 −2
Original line number Diff line number Diff line
@@ -18,7 +18,9 @@ deep look at the fundamental commands.
During this course you will learn unique benefits and concepts of Git as well
as its core features via extensive examples, hands-on exercises and mandatory
homework. The emphasis of the course is to prepare you for working on group
community upstream projects in enterprise. 
community upstream projects in enterprise. We want you to experience what it's
like to work on a Git project where multiple people contribute: this is what we
experience in our jobs every day.

## Lectors
* Irina Gulina (Senior Software Quality Engineer)
@@ -36,7 +38,7 @@ The course is open to all students: Bc, Mgr and PhD.
This would be the second run. The first one happened in Autumn 2022.

**IS course info**: https://is.muni.cz/predmet/fi/podzim2023/PV177  
**Lecture time**: TBD  
**Lecture time**: Group 1 10:00-11:40, Group 2 12:00-13:40
**Lecture room**: FI MU S505 Red Hat lab at Faculty of Informatics, Masaryk University (S505, note that the room is only available during lecture time)  
**Grading**: successfully complete 5/6 mandatory homeworks  
**ECTS Credits**: 2  
@@ -47,6 +49,33 @@ This would be the second run. The first one happened in Autumn 2022.
* Understand basic Computer Science concepts.
* Linux-based operating system is a big plus. You may get bonus points for Fedora Linux 😇

## Homeworks

### Homework 1

* Fork this repository
* Upload SSH keys to your account
* Comment your UCO in an issue in this repo for your respective group:
  0. https://gitlab.com/redhat/research/mastering-git/-/issues/2
  1. https://gitlab.com/redhat/research/mastering-git/-/issues/3

### Homework 2

* Create a merge request for this repo
* It has to come from your fork, and **not** from the main branch
* Feel free to improve some text, reword something, fix a typo, fix a bug in the homework check script (💰)
* Otherwise give us feedback inside session2_feedback/
  * Create a new file `<UCO>.txt`
* MR doesn't need to be merged to pass this homework

### Homework 3 (TBD)

We're gonna create some more MRs!

* [prep] we need to create up front some content that is not valid so people can fix it
* Find a pair & review each others contributions
* There needs to be at least a single interaction: explanation, clarification, request for changes

## Sylabus
(This will be polished during summer 2023 and will include materials)

hw.py

0 → 100755
+82 −0
Original line number Diff line number Diff line
#!/usr/bin/python3
"""
Homework check script.

Is it a good idea to make it open?
"""
import os
import sys
import ogr
from ogr.abstract import PRStatus
from ogr.exceptions import GitlabAPIException


class Homework:
    pass


class Item:
    def __init__(self, gitlab_service: ogr.GitlabService,  username: str):
        self.gitlab_service = gitlab_service
        self.username = username
        self.project = gitlab_service.get_project(namespace="redhat/research", repo="mastering-git")


class HasForkedMainRepo(Item):
    def check(self):
        try:
            # this doesn't do any calls yet
            fork = self.gitlab_service.get_project(repo="mastering-git", namespace=self.username)
            # this does
            fork.get_branches()
        except GitlabAPIException:
            return False
        else:
            return True


class HasPubkey(Item):
    def check(self):
        user = self.gitlab_service.gitlab_instance.users.list(username=self.username)[0]
        try:
            keys = user.keys.list()
            print(keys)
        except GitlabAPIException:
            return False
        else:
            return bool(keys)


class MRExists(Item):
    def check(self):
        prs = self.project.get_pr_list(PRStatus.all)
        for pr in prs:
            if pr.author == self.username:
                if pr.source_branch == 'main':
                    # we could halt here but there may be more MRs
                    # anyway, the request is to send the MR NOT from main
                    continue
                return True
        return False


class Homework1(Homework):
    items = (HasForkedMainRepo, HasPubkey)


class Homework2(Homework):
    items = (MRExists, )


def check_one(gitlab_username: str):
    gl = ogr.GitlabService(token=os.environ["GITLAB_TOKEN"])
    for HWKls in (Homework1, Homework2):
        for ItKls in HWKls.items:
            item = ItKls(gl, gitlab_username)
            print(f"{item.__class__.__name__}: {item.check()}")


# TODO: run for all course participants

if __name__ == '__main__':
    sys.exit(check_one(sys.argv[1]))

requirements.txt

0 → 100644
+1 −0
Original line number Diff line number Diff line
ogr
+1 −0
Original line number Diff line number Diff line
It's so hard to organize and deliver a University course, I learnt so much from this experience.