-- |
-- The actions API as documented at
-- <https://docs.github.com/en/rest/reference/actions>.

module GitHub.Endpoints.Actions.Artifacts (
    artifactsForR,
    artifactR,
    deleteArtifactR,
    downloadArtifactR,
    artifactsForWorkflowRunR,
    module GitHub.Data
    ) where

import GitHub.Data
import GitHub.Internal.Prelude
import Network.URI             (URI)
import Prelude ()

-- | List artifacts for repository.
-- See <https://docs.github.com/en/rest/reference/actions#list-artifacts-for-a-repository>
artifactsForR
    :: Name Owner
    -> Name Repo
    -> ArtifactMod
    -> FetchCount
    -> Request 'RA (WithTotalCount Artifact)
artifactsForR :: Name Owner
-> Name Repo
-> ArtifactMod
-> FetchCount
-> Request 'RA (WithTotalCount Artifact)
artifactsForR Name Owner
user Name Repo
repo ArtifactMod
opts = Paths
-> QueryString
-> FetchCount
-> Request 'RA (WithTotalCount Artifact)
forall a (t :: * -> *) b (mt :: MediaType (*)) (rw :: RW).
(a ~ t b, Foldable t, Semigroup a) =>
Paths -> QueryString -> FetchCount -> GenRequest mt rw a
PagedQuery
    [Text
"repos", Name Owner -> Text
forall a. IsPathPart a => a -> Text
toPathPart Name Owner
user, Name Repo -> Text
forall a. IsPathPart a => a -> Text
toPathPart Name Repo
repo, Text
"actions", Text
"artifacts"]
    (ArtifactMod -> QueryString
artifactModToQueryString ArtifactMod
opts)

-- | Get an artifact.
-- See <https://docs.github.com/en/rest/reference/actions#get-an-artifact>
artifactR :: Name Owner -> Name Repo -> Id Artifact -> Request 'RA Artifact
artifactR :: Name Owner -> Name Repo -> Id Artifact -> Request 'RA Artifact
artifactR Name Owner
user Name Repo
repo Id Artifact
artid =
    Paths -> QueryString -> Request 'RA Artifact
forall (mt :: RW) a. Paths -> QueryString -> Request mt a
query [Text
"repos", Name Owner -> Text
forall a. IsPathPart a => a -> Text
toPathPart Name Owner
user, Name Repo -> Text
forall a. IsPathPart a => a -> Text
toPathPart Name Repo
repo, Text
"actions", Text
"artifacts", Id Artifact -> Text
forall a. IsPathPart a => a -> Text
toPathPart Id Artifact
artid] []

-- | Delete an artifact.
-- See <https://docs.github.com/en/rest/reference/actions#delete-an-artifact>
deleteArtifactR :: Name Owner -> Name Repo -> Id Comment -> GenRequest 'MtUnit 'RW ()
deleteArtifactR :: Name Owner -> Name Repo -> Id Comment -> GenRequest 'MtUnit 'RW ()
deleteArtifactR Name Owner
user Name Repo
repo Id Comment
artid =
    CommandMethod -> Paths -> ByteString -> GenRequest 'MtUnit 'RW ()
forall (mt :: MediaType (*)) a.
CommandMethod -> Paths -> ByteString -> GenRequest mt 'RW a
Command CommandMethod
Delete Paths
parts ByteString
forall a. Monoid a => a
mempty
  where
    parts :: Paths
parts = [Text
"repos", Name Owner -> Text
forall a. IsPathPart a => a -> Text
toPathPart Name Owner
user, Name Repo -> Text
forall a. IsPathPart a => a -> Text
toPathPart Name Repo
repo, Text
"actions", Text
"artifacts", Id Comment -> Text
forall a. IsPathPart a => a -> Text
toPathPart Id Comment
artid]

-- | Download an artifact.
-- See <https://docs.github.com/en/rest/reference/actions#download-an-artifact>
downloadArtifactR :: Name Owner -> Name Repo -> Id Artifact -> GenRequest 'MtRedirect 'RW URI
downloadArtifactR :: Name Owner
-> Name Repo -> Id Artifact -> GenRequest 'MtRedirect 'RW URI
downloadArtifactR Name Owner
user Name Repo
repo Id Artifact
artid =
    Paths -> QueryString -> GenRequest 'MtRedirect 'RW URI
forall (mt :: MediaType (*)) (rw :: RW) a.
Paths -> QueryString -> GenRequest mt rw a
Query [Text
"repos", Name Owner -> Text
forall a. IsPathPart a => a -> Text
toPathPart Name Owner
user, Name Repo -> Text
forall a. IsPathPart a => a -> Text
toPathPart Name Repo
repo, Text
"actions", Text
"artifacts", Id Artifact -> Text
forall a. IsPathPart a => a -> Text
toPathPart Id Artifact
artid, Text
"zip"] []

-- | List artifacts for a workflow run.
-- See <https://docs.github.com/en/rest/reference/actions#list-workflow-run-artifacts>
artifactsForWorkflowRunR
    :: Name Owner
    -> Name Repo
    -> Id WorkflowRun
    -> FetchCount
    -> Request 'RA (WithTotalCount Artifact)
artifactsForWorkflowRunR :: Name Owner
-> Name Repo
-> Id WorkflowRun
-> FetchCount
-> Request 'RA (WithTotalCount Artifact)
artifactsForWorkflowRunR Name Owner
user Name Repo
repo Id WorkflowRun
runid  = Paths
-> QueryString
-> FetchCount
-> Request 'RA (WithTotalCount Artifact)
forall a (t :: * -> *) b (mt :: MediaType (*)) (rw :: RW).
(a ~ t b, Foldable t, Semigroup a) =>
Paths -> QueryString -> FetchCount -> GenRequest mt rw a
PagedQuery
    [Text
"repos", Name Owner -> Text
forall a. IsPathPart a => a -> Text
toPathPart Name Owner
user, Name Repo -> Text
forall a. IsPathPart a => a -> Text
toPathPart Name Repo
repo, Text
"actions", Text
"runs", Id WorkflowRun -> Text
forall a. IsPathPart a => a -> Text
toPathPart Id WorkflowRun
runid, Text
"artifacts"]
    []