Compare commits

..

2 Commits

Author SHA1 Message Date
5412c3ea09 Add DevOps OAuth2 flow details to README
All checks were successful
/ unit-tests (push) Successful in 10s
2025-11-09 18:45:10 +01:00
6e16cebeea Add branch support to Item class and enhance get_content method 2025-11-09 18:44:52 +01:00
2 changed files with 33 additions and 6 deletions

View File

@@ -3,3 +3,11 @@
[![Unit Tests](https://gitea.koszewscy.waw.pl/slawek/docs-harvester/actions/workflows/unit-tests.yml/badge.svg)](https://gitea.koszewscy.waw.pl/slawek/docs-harvester/actions?workflow=unit-tests.yml)
This project is designed to harvest and process Markdown documentation files from Git repositories.
## DevOps OAuth2 Flow
Type: **oauth2**
Flow: **accessCode**
Authorization URL: `https://app.vssps.visualstudio.com/oauth2/authorize&response_type=Assertion`
Token URL: `https://app.vssps.visualstudio.com/oauth2/token?client_assertion_type=urn:ietf:params:oauth:client-assertion-type:jwt-bearer&grant_type=urn:ietf:params:oauth:grant-type:jwt-bearer`
Scopes: `vso.code`

View File

@@ -243,8 +243,16 @@ class Item():
def __init__(self, repository: Repository, **kwargs):
self._repository = repository
self.from_args(**kwargs) # type: ignore[attr-defined]
if "branch" in kwargs:
self._branch = kwargs.get("branch")
log_entity_creation(log, Item, self.path)
@property
def branch(self):
if hasattr(self, "_branch"):
return getattr(self, "_branch")
return None
def get_auto_properties(self):
r = self._repository._project.organization.get_path(
path=f"{self._repository._project.id}/_apis/git/repositories/{self._repository.id}/items",
@@ -256,17 +264,28 @@ class Item():
)
self.from_json(r.json()) # type: ignore[attr-defined]
def get_content(self) -> bytes:
"""Get the content of the item if it is a file."""
def get_content(self, branch: str | None = None, commit: str | None = None, tag: str | None = None) -> bytes:
"""Get the content of the item with optional branch, commit, or tag."""
if self.git_object_type != "blob": # type: ignore[attr-defined]
raise ValueError("Content can only be fetched for blob items.")
params = { "path": self.path, "recursionLevel": "none" }
if self.branch and branch is None:
branch = self.branch
if branch:
params["version"] = branch
params["versionType"] = "branch"
elif tag:
params["version"] = tag
params["versionType"] = "tag"
elif commit:
params["version"] = commit
params["versionType"] = "commit"
r = self._repository._project.organization.get_path(
path=f"{self._repository._project.id}/_apis/git/repositories/{self._repository.id}/items",
params={
"path": self.path,
"recursionLevel": "none"
}
params=params
)
return r.content