Skip to content

Add unwatch request #473

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
17 changes: 17 additions & 0 deletions samples/Repos/Watching/Unwatch.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{-# LANGUAGE OverloadedStrings #-}

module Main where

import qualified GitHub as GH
import qualified Data.Text as T
import qualified Data.Text.IO as T

main :: IO ()
main = do
let auth = GH.BasicAuth "<login>" "<pass>"
owner = "haskell-github"
repo = "github"
result <- GH.github auth GH.unwatchRepoR (GH.mkOwnerName owner) (GH.mkRepoName repo)
case result of
Left err -> putStrLn $ "Error: " ++ show err
Right () -> T.putStrLn $ T.concat ["No longer watching: ", owner, "/", repo]
6 changes: 6 additions & 0 deletions samples/github-samples.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,12 @@ executable github-teaminfo-for
main-is: TeamInfoFor.hs
hs-source-dirs: Teams

executable github-unwatch-repo
import: deps
main-is: Unwatch.hs
ghc-options: -Wall -threaded
hs-source-dirs: Repos/Watching

-- executable github-create-public-ssh-key
-- import: deps
-- main-is: CreatePublicSSHKey.hs
Expand Down
2 changes: 1 addition & 1 deletion src/GitHub.hs
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ module GitHub (
--
-- * Query a Repository Subscription
-- * Set a Repository Subscription
-- * Delete a Repository Subscription
watchersForR,
reposWatchedByR,
unwatchRepoR,

-- * Gists
-- | See <https://developer.github.com/v3/gists/>
Expand Down
7 changes: 7 additions & 0 deletions src/GitHub/Endpoints/Activity/Watching.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
module GitHub.Endpoints.Activity.Watching (
watchersForR,
reposWatchedByR,
unwatchRepoR,
module GitHub.Data,
) where

Expand All @@ -27,3 +28,9 @@ watchersForR user repo limit =
reposWatchedByR :: Name Owner -> FetchCount -> Request k (Vector Repo)
reposWatchedByR user =
pagedQuery ["users", toPathPart user, "subscriptions"] []

-- | Stop watching repository.
-- See <https://docs.github.com/en/rest/reference/activity#delete-a-repository-subscription>
unwatchRepoR :: Name Owner -> Name Repo -> Request 'RW ()
unwatchRepoR owner repo =
command Delete ["repos", toPathPart owner, toPathPart repo, "subscription"] mempty