Skip to content

Commit a3fdb3c

Browse files
authored
Merge pull request #7 from SAN-MUYUN/add-on/autograder-tag-doc
update DG on autograder TagHelper and GitAutograderTag
2 parents ac47ea7 + 5245a2b commit a3fdb3c

1 file changed

Lines changed: 41 additions & 0 deletions

File tree

docs/libraries/git-autograder.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,47 @@ if not origin.is_for_repo("git-mastery", "exercises"):
148148
raise exercise.wrong_answer(["Your remote 'origin' does not point to the correct repository."])
149149
```
150150

151+
### `exercise.repo.tags``TagHelper`
152+
153+
```python
154+
tag = exercise.repo.tags.tag("v1.0.0") # raises if missing
155+
tag = exercise.repo.tags.tag_or_none("v1.0.0") # returns None if missing
156+
exists = exercise.repo.tags.has_tag("v1.0.0")
157+
158+
remote_tags = exercise.repo.tags.remote_tag_names("origin") # raises if remote is missing or tags cannot be queried
159+
remote_tags = exercise.repo.tags.remote_tag_names_or_none("origin") # returns None on missing remote or query failure
160+
```
161+
162+
#### `GitAutograderTag`
163+
164+
| Property / Method | Description |
165+
|---|---|
166+
| `tag.name` | Tag name |
167+
| `tag.commit` | Commit pointed to by this tag (`GitAutograderCommit`) |
168+
| `tag.is_annotated` | True if this is an annotated tag |
169+
| `tag.is_lightweight` | True if this is a lightweight tag |
170+
| `tag.message_or_none(strip=True, lower=False)` | Annotated tag message, or `None` for lightweight tags |
171+
| `tag.points_to(commit)` | True if this tag points to the given commit |
172+
173+
Example — check that a required local tag exists:
174+
175+
```python
176+
if not exercise.repo.tags.has_tag("v1.0.0"):
177+
raise exercise.wrong_answer(["Tag 'v1.0.0' is missing."])
178+
```
179+
180+
Example — verify that the start tag exists on `origin`:
181+
182+
```python
183+
main = exercise.repo.branches.branch("main")
184+
first_commit = main.commits[-1]
185+
start_tag = f"git-mastery-start-{first_commit.hexsha[:7]}"
186+
187+
remote_tags = exercise.repo.tags.remote_tag_names_or_none("origin")
188+
if remote_tags is None or start_tag not in remote_tags:
189+
raise exercise.wrong_answer([f"Missing start tag on origin: {start_tag}"])
190+
```
191+
151192
### `exercise.repo.files``FileHelper`
152193

153194
```python

0 commit comments

Comments
 (0)