Skip to content

Commit ee8d1b9

Browse files
committed
Add endpoints for (un)starring repositories
1 parent 05eef68 commit ee8d1b9

4 files changed

Lines changed: 62 additions & 2 deletions

File tree

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{-# LANGUAGE OverloadedStrings #-}
2+
module StarRepo where
3+
4+
import qualified GitHub.Endpoints.Activity.Starring as GH
5+
6+
import qualified Data.Text as T
7+
import qualified Data.Text.IO as T
8+
9+
main :: IO ()
10+
main = do
11+
let owner = "phadej"
12+
repo = "github"
13+
result <- GH.starRepo (GH.OAuth "your-token")
14+
(GH.mkOwnerName owner) (GH.mkRepoName repo)
15+
case result of
16+
Left err -> putStrLn $ "Error: " ++ show err
17+
Right () -> T.putStrLn $ T.concat ["Starred: ", owner, "/", repo]
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{-# LANGUAGE OverloadedStrings #-}
2+
module UnstarRepo where
3+
4+
import qualified GitHub.Endpoints.Activity.Starring as GH
5+
6+
import qualified Data.Text as T
7+
import qualified Data.Text.IO as T
8+
9+
main :: IO ()
10+
main = do
11+
let owner = "phadej"
12+
repo = "github"
13+
result <- GH.unstarRepo (GH.OAuth "your-token")
14+
(GH.mkOwnerName owner) (GH.mkRepoName repo)
15+
case result of
16+
Left err -> putStrLn $ "Error: " ++ show err
17+
Right () -> T.putStrLn $ T.concat ["Unstarred: ", owner, "/", repo]

src/GitHub.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ module GitHub (
2525
-- Missing endpoints:
2626
--
2727
-- * Check if you are starring a repository
28-
-- * Star a repository
29-
-- * Unstar a repository
3028
stargazersForR,
3129
reposStarredByR,
3230
myStarredR,
3331
myStarredAcceptStarR,
32+
starRepoR,
33+
unstarRepoR,
3434

3535
-- ** Watching
3636
-- | See <https://developer.github.com/v3/activity/>

src/GitHub/Endpoints/Activity/Starring.hs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ module GitHub.Endpoints.Activity.Starring (
1414
myStarredR,
1515
myStarredAcceptStar,
1616
myStarredAcceptStarR,
17+
starRepo,
18+
starRepoR,
19+
unstarRepo,
20+
unstarRepoR,
1721
module GitHub.Data,
1822
) where
1923

@@ -69,3 +73,25 @@ myStarredAcceptStar auth =
6973
-- See <https://developer.github.com/v3/activity/starring/#alternative-response-with-star-creation-timestamps-1>
7074
myStarredAcceptStarR :: FetchCount -> Request 'RA (Vector RepoStarred)
7175
myStarredAcceptStarR = HeaderQuery [("Accept", "application/vnd.github.v3.star+json")] . PagedQuery ["user", "starred"] []
76+
77+
-- | Star a repo by the authenticated user.
78+
starRepo :: Auth -> Name Owner -> Name Repo -> IO (Either Error ())
79+
starRepo auth user repo = executeRequest auth $ starRepoR user repo
80+
81+
-- | Star a repo by the authenticated user.
82+
-- See <https://developer.github.com/v3/activity/starring/#star-a-repository>
83+
starRepoR :: Name Owner -> Name Repo -> Request 'RW ()
84+
starRepoR user repo = command Put' paths mempty
85+
where
86+
paths = ["user", "starred", toPathPart user, toPathPart repo]
87+
88+
-- | Unstar a repo by the authenticated user.
89+
unstarRepo :: Auth -> Name Owner -> Name Repo -> IO (Either Error ())
90+
unstarRepo auth user repo = executeRequest auth $ unstarRepoR user repo
91+
92+
-- | Unstar a repo by the authenticated user.
93+
-- See <https://developer.github.com/v3/activity/starring/#unstar-a-repository>
94+
unstarRepoR :: Name Owner -> Name Repo -> Request 'RW ()
95+
unstarRepoR user repo = command Delete paths mempty
96+
where
97+
paths = ["user", "starred", toPathPart user, toPathPart repo]

0 commit comments

Comments
 (0)