예제 #1
0
    def download_zip(self, branch: str, output_path: str) -> None:
        """Download the zip of the branch specified.

        :param str branch: The name of the branch to download.
        :param str output_path: The path to write the output to.

        :raises ADOException: If the output path already exists
        :raises ADOHTTPException: If we fail to fetch the zip for any reason
        """

        self.log.debug(f"Downloading branch: {branch}")
        request_url = (
            f"{self.http_client.base_url()}/git/repositories/{self._context.repository_id}/Items?"
        )

        parameters = {
            "path": "/",
            "versionDescriptor[versionOptions]": "0",
            "versionDescriptor[versionType]": "0",
            "versionDescriptor[version]": branch,
            "resolveLfs": "true",
            "$format": "zip",
            "api-version": "5.0-preview.1",
        }

        request_url += urllib.parse.urlencode(parameters)

        if os.path.exists(output_path):
            raise ADOException("The output path already exists")

        with self.http_client.get(request_url, stream=True) as response:
            download_from_response_stream(response=response,
                                          output_path=output_path,
                                          log=self.log)
예제 #2
0
    def download_artifact(self, *, project_id: str, build_id: int,
                          artifact_name: str, output_path: str) -> None:
        """Download an artifact from a build.

        :param str project_id: The ID of the project
        :param build_id: The ID of the build
        :param artifact_name: The name of the artifact to fetch
        :param str output_path: The path to write the output to.
        """

        parameters = {
            "artifactName": artifact_name,
            "$format": "zip",
            "api-version": "4.1",
        }

        request_url = f"{self.http_client.api_endpoint(project_id=project_id)}/build/builds/{build_id}/artifacts?"
        request_url += urllib.parse.urlencode(parameters)

        self.log.debug(
            f"Fetching artifact {artifact_name} from build {build_id}...")

        with self.http_client.get(request_url, stream=True) as response:
            download_from_response_stream(response=response,
                                          output_path=output_path,
                                          log=self.log)
예제 #3
0
    def get_blobs(self, *, blob_ids: List[str],
                  output_path: str) -> ADOResponse:
        """Get a git item.

        All non-specified options use the ADO default.

        :param List[str] blob_ids: The SHA1s of the blobs
        :param str output_path: The location to write out the zip to
        """

        self.log.debug(f"Getting blobs")

        request_url = self.http_client.api_endpoint(
            is_default_collection=False)
        request_url += f"/git/repositories/{self.context.repository_id}/blobs?api-version=5.1"

        if os.path.exists(output_path):
            raise ADOException("The output path already exists")

        with self.http_client.post(
                request_url,
                additional_headers={"Accept": "application/zip"},
                stream=True,
                json_data=blob_ids,
        ) as response:
            download_from_response_stream(response=response,
                                          output_path=output_path,
                                          log=self.log)