Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
91b9f67
Implement actions->artifacts API.
K0Te Jun 22, 2021
f1e9513
Up
K0Te Jul 16, 2022
b1ab2df
Cleanup
K0Te Jul 17, 2022
d094b17
Actions - cache.
K0Te Jul 17, 2022
7b18e83
Actions - artifacts and cache.
K0Te Oct 31, 2022
9cf8f3b
Secrets
K0Te Nov 11, 2022
e74a861
Workflows.
K0Te Nov 12, 2022
6352003
WorkflowJobs.
K0Te Nov 12, 2022
afad670
Merge branch 'master' into github-actions-2
andreasabel Nov 12, 2022
2811abb
WorkflowRuns.
K0Te Nov 13, 2022
0661ca1
Format
K0Te Nov 13, 2022
ed61cc1
Artifacts QA.
K0Te Nov 14, 2022
50f7fa1
Cache QA.
K0Te Nov 14, 2022
d02bed9
Secrets QA.
K0Te Nov 21, 2022
90ac4b4
WorkflowJobs QA.
K0Te Nov 21, 2022
d56b38d
Workflows QA.
K0Te Nov 21, 2022
1012da2
Format.
K0Te Nov 21, 2022
3f83775
Drop slack-related files.
K0Te Nov 21, 2022
7212468
Format JSON
K0Te Nov 21, 2022
72acb62
Support workflow name in workflowRunsForWorkflowR.
K0Te Nov 28, 2022
c329f88
Support workflow name in Workflows.hs.
K0Te Nov 28, 2022
42418cc
Fix
K0Te Nov 28, 2022
7d7ea3c
Fix
K0Te Nov 28, 2022
c6833bf
Do not parse pull requests from workflow runs.
K0Te Nov 30, 2022
4c995da
Avoid parsing 'trigerring_actor', it is sometimes missing.
K0Te Nov 30, 2022
7838a81
Fix workflow run conclusion parsing.
K0Te Nov 30, 2022
0071e3d
Merge branch 'master' into github-actions-2
andreasabel Jun 23, 2023
a24393c
Whitespace and lexical changes only
andreasabel Jun 23, 2023
148d0f4
Merge branch 'master' into github-actions-2
andreasabel Jun 23, 2023
c4ac51c
Remove outdated maintainer from module headers
andreasabel Jun 23, 2023
21f2904
Whitespace: align code
andreasabel Jun 23, 2023
62bec02
Merge branch 'master' into github-actions-2
andreasabel Jun 23, 2023
9e2b148
Bump cabal-version to 2.4 for globbing
andreasabel Jun 23, 2023
6b9d05e
Cosmetics: use (<&>)
andreasabel Jun 23, 2023
6a03ecc
Restore upper bounds for openssl etc. in .cabal file
andreasabel Jun 23, 2023
2a4ddc0
Whitespace
andreasabel Jun 23, 2023
8efa8b6
Add haddocks for WithTotalCount
andreasabel Jun 24, 2023
9837d4c
Changelog for PR #459
andreasabel Jun 24, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Up
  • Loading branch information
K0Te committed Jul 16, 2022
commit f1e951373e7ec7e7f08c0b16c2d917334a6eb61d
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ cabal.sandbox.config
run.sh
src/hightlight.js
src/style.css
.DS_Store
7 changes: 4 additions & 3 deletions github.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ library
GitHub.Data.Webhooks
GitHub.Data.Webhooks.Validate
GitHub.Endpoints.Actions.Artifacts
GitHub.Endpoints.Actions.Cache
GitHub.Endpoints.Activity.Events
GitHub.Endpoints.Activity.Notifications
GitHub.Endpoints.Activity.Starring
Expand Down Expand Up @@ -201,9 +202,9 @@ library

if flag(openssl)
build-depends:
HsOpenSSL >=0.11.4.16 && <0.12
, HsOpenSSL-x509-system >=0.1.0.3 && <0.2
, http-client-openssl >=0.2.2.0 && <0.4
HsOpenSSL >=0.11.4.16 && <1.12
, HsOpenSSL-x509-system >=0.1.0.3 && <1.2
, http-client-openssl >=0.2.2.0 && <1.4

else
build-depends:
Expand Down
4 changes: 4 additions & 0 deletions hie.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
cradle:
stack:
- path: "./src"
component: "github:lib"
103 changes: 86 additions & 17 deletions src/GitHub/Data/Actions.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module GitHub.Data.Actions (
PaginatedWithTotalCount(..),
WithTotalCount(..),
WorkflowRun,
Cache(..),
) where

import GHC.TypeLits
Expand All @@ -24,6 +25,32 @@ import Prelude ()
import Data.Data (Proxy (..))
import qualified Data.Text as T

-------------------------------------------------------------------------------
-- Common
-------------------------------------------------------------------------------

data PaginatedWithTotalCount a (tag :: Symbol) = PaginatedWithTotalCount
{ paginatedWithTotalCountItems :: !(Vector a)
, paginatedWithTotalCountTotalCount :: !Int
}

data WithTotalCount a = WithTotalCount
{ withTotalCountItems :: !(Vector a)
, withTotalCountTotalCount :: !Int
} deriving (Show, Data, Typeable, Eq, Ord, Generic)

instance Semigroup (WithTotalCount a) where
(WithTotalCount items1 count1) <> (WithTotalCount items2 _) =
WithTotalCount (items1 <> items2) count1

instance Foldable WithTotalCount where
foldMap f (WithTotalCount items _) = foldMap f items


-------------------------------------------------------------------------------
-- Artifact
-------------------------------------------------------------------------------

data Artifact = Artifact
{ artifactArchiveDownloadUrl :: !URL
, artifactCreatedAt :: !UTCTime
Expand All @@ -44,23 +71,6 @@ data ArtifactList = ArtifactList
}
deriving (Show, Data, Typeable, Eq, Ord, Generic)

data PaginatedWithTotalCount a (tag :: Symbol) = PaginatedWithTotalCount
{ paginatedWithTotalCountItems :: !(Vector a)
, paginatedWithTotalCountTotalCount :: !Int
}

data WithTotalCount a = WithTotalCount
{ withTotalCountItems :: !(Vector a)
, withTotalCountTotalCount :: !Int
} deriving (Show, Data, Typeable, Eq, Ord, Generic)

instance Semigroup (WithTotalCount a) where
(WithTotalCount items1 count1) <> (WithTotalCount items2 _) =
WithTotalCount (items1 <> items2) count1

instance Foldable WithTotalCount where
foldMap f (WithTotalCount items _) = foldMap f items

data Workflow
data WorkflowRun

Expand Down Expand Up @@ -95,3 +105,62 @@ instance FromJSON (WithTotalCount Artifact) where
parseJSON = withObject "ArtifactList" $ \o -> WithTotalCount
<$> o .: "artifacts"
<*> o .: "total_count"


-------------------------------------------------------------------------------
-- Cache
-------------------------------------------------------------------------------

data Cache = Cache
{ cacheId :: !(Id Cache)
, cacheRef :: !Text
, cacheKey :: !Text
, cacheVersion :: !Text
, cacheLastAccessedAt :: !UTCTime
, cacheCreatedAt :: !UTCTime
, cacheSizeInBytes :: !Int
}
deriving (Show, Data, Typeable, Eq, Ord, Generic)

-- data CacheList = CacheList
-- { cacheListCaches :: !(Vector Cache)
-- , cacheListTotalCount :: !Int
-- }
-- deriving (Show, Data, Typeable, Eq, Ord, Generic)

-- data Workflow
-- data WorkflowRun

-- -------------------------------------------------------------------------------
-- -- JSON instances
-- -------------------------------------------------------------------------------

instance FromJSON Cache where
parseJSON = withObject "Cache" $ \o -> Cache
<$> o .: "id"
<*> o .: "ref"
<*> o .: "key"
<*> o .: "version"
<*> o .: "last_accessed_at"
<*> o .: "created_at"
<*> o .: "size_in_bytes"

-- instance FromJSON CacheList where
-- parseJSON = withObject "CacheList" $ \o -> CacheList
-- <$> o .: "actions_caches"
-- <*> o .: "total_count"

instance FromJSON (WithTotalCount Cache) where
parseJSON = withObject "CacheList" $ \o -> WithTotalCount
<$> o .: "actions_caches"
<*> o .: "total_count"

-- instance (FromJSON a, KnownSymbol l) => FromJSON (PaginatedWithTotalCount a l) where
-- parseJSON = withObject "PaginatedWithTotalCount" $ \o -> PaginatedWithTotalCount
-- <$> o .: T.pack (symbolVal (Proxy :: Proxy l))
-- <*> o .: "total_count"

-- instance FromJSON (WithTotalCount Artifact) where
-- parseJSON = withObject "ArtifactList" $ \o -> WithTotalCount
-- <$> o .: "artifacts"
-- <*> o .: "total_count"
123 changes: 123 additions & 0 deletions src/GitHub/Data/Options.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE LambdaCase #-}
-----------------------------------------------------------------------------
-- |
-- License : BSD-3-Clause
Expand Down Expand Up @@ -44,6 +45,18 @@ module GitHub.Data.Options (
optionsIrrelevantAssignee,
optionsAnyAssignee,
optionsNoAssignee,
-- * Actions cache
CacheMod,
cacheModToQueryString,
optionsRef,
optionsNoRef,
optionsKey,
optionsNoKey,
optionsDirectionAsc,
optionsDirectionDesc,
sortByCreatedAt,
sortByLastAccessedAt,
sortBySizeInBytes,
-- * Data
IssueState (..),
MergeableState (..),
Expand Down Expand Up @@ -180,6 +193,18 @@ data FilterBy a
deriving
(Eq, Ord, Show, Generic, Typeable, Data)

-- Actions cache

data SortCache
= SortCacheCreatedAt
| SortCacheLastAccessedAt
| SortCacheSizeInBytes
deriving
(Eq, Ord, Show, Enum, Bounded, Generic, Typeable, Data)

instance NFData SortCache where rnf = genericRnf
instance Binary SortCache

-------------------------------------------------------------------------------
-- Classes
-------------------------------------------------------------------------------
Expand Down Expand Up @@ -607,3 +632,101 @@ optionsAnyAssignee = IssueRepoMod $ \opts ->
optionsNoAssignee :: IssueRepoMod
optionsNoAssignee = IssueRepoMod $ \opts ->
opts { issueRepoOptionsAssignee = FilterNone }

-------------------------------------------------------------------------------
-- Actions cache
-------------------------------------------------------------------------------

-- | See <https://docs.github.com/en/rest/actions/cache#list-github-actions-caches-for-a-repository>.
data CacheOptions = CacheOptions
{ cacheOptionsRef :: !(Maybe Text)
, cacheOptionsKey :: !(Maybe Text)
, cacheOptionsSort :: !(Maybe SortCache)
, cacheOptionsDirection :: !(Maybe SortDirection)
}
deriving
(Eq, Ord, Show, Generic, Typeable, Data)

defaultCacheOptions :: CacheOptions
defaultCacheOptions = CacheOptions
{ cacheOptionsRef = Nothing
, cacheOptionsKey = Nothing
, cacheOptionsSort = Nothing
, cacheOptionsDirection = Nothing
}

-- | See <https://docs.github.com/en/rest/actions/cache#list-github-actions-caches-for-a-repository>.
newtype CacheMod = CacheMod (CacheOptions -> CacheOptions)

instance Semigroup CacheMod where
CacheMod f <> CacheMod g = CacheMod (g . f)

instance Monoid CacheMod where
mempty = CacheMod id
mappend = (<>)

toCacheOptions :: CacheMod -> CacheOptions
toCacheOptions (CacheMod f) = f defaultCacheOptions

cacheModToQueryString :: CacheMod -> QueryString
cacheModToQueryString = cacheOptionsToQueryString . toCacheOptions

cacheOptionsToQueryString :: CacheOptions -> QueryString
cacheOptionsToQueryString (CacheOptions ref key sort dir) =
catMaybes
[ mk "ref" <$> ref'
, mk "key" <$> key'
, mk "sort" <$> sort'
, mk "directions" <$> direction'
]
where
mk k v = (k, Just v)
sort' = fmap (\case
SortCacheCreatedAt -> "created_at"
SortCacheLastAccessedAt -> "last_accessed_at"
SortCacheSizeInBytes -> "size_in_bytes") sort
direction' = fmap (\case
SortDescending -> "desc"
SortAscending -> "asc") dir
ref' = fmap TE.encodeUtf8 ref
key' = fmap TE.encodeUtf8 key

-------------------------------------------------------------------------------
-- Pull request modifiers
-------------------------------------------------------------------------------

optionsRef :: Text -> CacheMod
optionsRef x = CacheMod $ \opts ->
opts { cacheOptionsRef = Just x }

optionsNoRef :: CacheMod
optionsNoRef = CacheMod $ \opts ->
opts { cacheOptionsRef = Nothing }

optionsKey :: Text -> CacheMod
optionsKey x = CacheMod $ \opts ->
opts { cacheOptionsKey = Just x }

optionsNoKey :: CacheMod
optionsNoKey = CacheMod $ \opts ->
opts { cacheOptionsKey = Nothing }

optionsDirectionAsc :: CacheMod
optionsDirectionAsc = CacheMod $ \opts ->
opts { cacheOptionsDirection = Just SortAscending }

optionsDirectionDesc :: CacheMod
optionsDirectionDesc = CacheMod $ \opts ->
opts { cacheOptionsDirection = Just SortDescending }

sortByCreatedAt :: CacheMod
sortByCreatedAt = CacheMod $ \opts ->
opts { cacheOptionsSort = Just SortCacheCreatedAt }

sortByLastAccessedAt :: CacheMod
sortByLastAccessedAt = CacheMod $ \opts ->
opts { cacheOptionsSort = Just SortCacheLastAccessedAt }

sortBySizeInBytes :: CacheMod
sortBySizeInBytes = CacheMod $ \opts ->
opts { cacheOptionsSort = Just SortCacheSizeInBytes }
73 changes: 73 additions & 0 deletions src/GitHub/Endpoints/Actions/Cache.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
-----------------------------------------------------------------------------
-- |
-- License : BSD-3-Clause
-- Maintainer : Oleg Grenrus <[email protected]>
--
-- The actions API as documented at
-- <https://docs.github.com/en/rest/reference/actions>.
module GitHub.Endpoints.Actions.Cache (
cachesForRepoR,
deleteCacheR,
module GitHub.Data
) where

import GitHub.Data
import GitHub.Internal.Prelude
import Network.URI (URI)
import Prelude ()
-- import GitHub.Data.Actions (ActionWorkflow, ActionWorkflowResult, ActionWorkflowRun, Workflow, ActionWorkflowRunResult, CreateWorkflowDispatchEvent)

-- -- | List artifacts for repository.
-- -- See <https://docs.github.com/en/rest/reference/actions#list-artifacts-for-a-repository>
-- artifactsForR
-- :: Name Owner
-- -> Name Repo
-- -> FetchCount
-- -> Request k (WithTotalCount Artifact)
-- artifactsForR user repo = PagedQuery
-- ["repos", toPathPart user, toPathPart repo, "actions", "artifacts"]
-- []


-- -- | Query a single artifact.
-- -- See <https://docs.github.com/en/rest/reference/actions#get-an-artifact>
-- artifactR :: Name Owner -> Name Repo -> Id Artifact -> Request k Artifact
-- artifactR user repo artid =
-- query ["repos", toPathPart user, toPathPart repo, "actions", "artifacts", toPathPart 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 user repo artid =
-- Query ["repos", toPathPart user, toPathPart repo, "actions", "artifacts", toPathPart artid, "zip"] []

-- | List the GitHub Actions caches for a repository.
-- See <https://docs.github.com/en/rest/actions/cache#list-github-actions-caches-for-a-repository>
cachesForRepoR
:: Name Owner
-> Name Repo
-> CacheMod
-> FetchCount
-> GenRequest 'MtJSON 'RA (WithTotalCount Cache)
cachesForRepoR user repo opts = PagedQuery
["repos", toPathPart user, toPathPart repo, "actions", "caches"]
(cacheModToQueryString opts)

-- | Delete GitHub Actions cache for a repository.
-- See <https://docs.github.com/en/rest/actions/cache#delete-github-actions-caches-for-a-repository-using-a-cache-key>
-- TODO: No querystring for Commands???
-- TODO: return value
-- deleteCachesKeyR :: Name Owner -> Name Repo -> String -> Maybe String -> GenRequest 'MtUnit 'RW ()
-- deleteCachesKeyR user repo key ref =
-- Command Delete parts mempty
-- where
-- parts = ["repos", toPathPart user, toPathPart repo, "actions", "caches"]

-- | Delete GitHub Actions cache for a repository.
-- See <https://docs.github.com/en/rest/actions/cache#delete-a-github-actions-cache-for-a-repository-using-a-cache-id>
deleteCacheR :: Name Owner -> Name Repo -> Id Cache -> GenRequest 'MtUnit 'RW ()
deleteCacheR user repo cacheid =
Command Delete parts mempty
where
parts = ["repos", toPathPart user, toPathPart repo, "actions", "caches", toPathPart cacheid]
Loading