Skip to content

Commit 88034da

Browse files
committed
Exercise(tags-add): add download and verify (tag v1.0.0)
1 parent 3f000ca commit 88034da

File tree

8 files changed

+94
-0
lines changed

8 files changed

+94
-0
lines changed

tags_add/.gitmastery-exercise.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"exercise_name": "tags-add",
3+
"tags": [
4+
"tags"
5+
],
6+
"requires_git": true,
7+
"requires_github": false,
8+
"base_files": {},
9+
"exercise_repo": {
10+
"repo_type": "local",
11+
"repo_name": "project",
12+
"repo_title": null,
13+
"create_fork": false,
14+
"init": true
15+
}
16+
}

tags_add/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# tags-add
2+
3+
<!--- Insert exercise description -->
4+
5+
## Task
6+
7+
<!--- Insert exercise task, simplify what needs to be done -->
8+
9+
## Hints
10+
11+
<!--- Insert hints here -->
12+
<!---
13+
Use Github Markdown's collapsible content:
14+
<details>
15+
<summary>...</summary>
16+
...
17+
</details>
18+
-->

tags_add/__init__.py

Whitespace-only changes.

tags_add/download.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from exercise_utils.file import create_or_update_file
2+
from exercise_utils.git import add, commit
3+
from exercise_utils.gitmastery import create_start_tag
4+
5+
__resources__ = []
6+
7+
def setup(verbose: bool = False):
8+
create_or_update_file("README.md", "# T4L2: Add a tag\n")
9+
add(["README.md"], verbose)
10+
commit("chore: init README", verbose)
11+
12+
create_or_update_file("main.txt", "v1 content\n")
13+
add(["main.txt"], verbose)
14+
commit("feat: initial content", verbose)
15+
16+
create_start_tag(verbose)

tags_add/tests/__init__.py

Whitespace-only changes.

tags_add/tests/specs/base.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
initialization:
2+
steps:
3+
- type: commit
4+
empty: true
5+
message: Empty commit
6+
id: start

tags_add/tests/test_verify.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from git_autograder import GitAutograderTestLoader
2+
3+
from ..verify import verify
4+
5+
REPOSITORY_NAME = "tags-add"
6+
7+
loader = GitAutograderTestLoader(__file__, REPOSITORY_NAME, verify)
8+
9+
10+
def test_base():
11+
with loader.load("specs/base.yml", "start"):
12+
pass

tags_add/verify.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from typing import List
2+
from git_autograder.core import GitAutograderExercise, GitAutograderStatus
3+
4+
MSG_NO_TAG = "Tag 'v1.0.0' was not found."
5+
MSG_NOT_AT_HEAD = "Tag 'v1.0.0' does not point to HEAD."
6+
7+
def verify(exercise: GitAutograderExercise):
8+
"""
9+
Pass condition:
10+
1) exist 1.0.0 tag
11+
2) the tag is pointing to current head
12+
"""
13+
repo = exercise.repo.repo
14+
target = next((t for t in repo.tags if t.name == "v1.0.0"), None)
15+
16+
messages: List[str] = []
17+
status = GitAutograderStatus.SUCCESSFUL
18+
19+
if target is None:
20+
messages.append(MSG_NO_TAG)
21+
status = GitAutograderStatus.FAILED
22+
elif target.commit.hexsha != repo.head.commit.hexsha:
23+
messages.append(MSG_NOT_AT_HEAD)
24+
status = GitAutograderStatus.FAILED
25+
26+
return exercise.to_output(messages, status)

0 commit comments

Comments
 (0)