Skip to content

Commit

Permalink
[#45] Add syncWithGithub function
Browse files Browse the repository at this point in the history
Resolves #45
  • Loading branch information
rashadg1030 committed Aug 8, 2019
1 parent c532a0b commit 5f29295
Showing 1 changed file with 11 additions and 44 deletions.
55 changes: 11 additions & 44 deletions src/IW/Sync/Update.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ data and insert it into the database.
-}

module IW.Sync.Update
( sync
( syncWithGithub
) where

import Control.Monad.IO.Unlift (MonadUnliftIO)
import UnliftIO.Async (mapConcurrently_)
import UnliftIO.Async (async, mapConcurrently_, wait)

import IW.App (WithError)
import IW.Core.Repo (Repo (..))
Expand All @@ -18,7 +18,7 @@ import IW.Sync.Search (searchAllHaskellRepos, searchAllHaskellIssues)
import IW.Time (getToday)


sync
syncWithGithub
:: forall env m.
( MonadCabal m
, MonadUnliftIO m
Expand All @@ -28,34 +28,20 @@ sync
)
=> Integer -- ^ The starting date interval used in the search function
-> m ()
sync interval = do
syncWithGithub interval = do
log I "Starting synchronization of all repositories and issues..."
syncRepos interval
syncIssues interval
log I "All repositories and issues successfully synchronized"

-- | This function fetches all repos from the GitHub API, downloads their @.cabal@ files,
-- and upserts them into the database.
syncRepos
:: forall env m.
( MonadCabal m
, MonadUnliftIO m
, WithDb env m
, WithLog env m
, WithError m
)
=> Integer
-> m ()
syncRepos interval = do
log I "Starting synchronization of repositories..."
today <- liftIO getToday
log I "Searching for all Haskell repositories..."
repos <- searchAllHaskellRepos today interval
log I "Upserting repositories into the database..."
upsertRepos repos
log I "Updating all repositories' category fields..."
mapConcurrently_ syncCategories repos
log I "Repositories successfully synchronized"
populateCategoriesAsync <- async $ mapConcurrently_ syncCategories repos
log I "Searching for all Haskell issues..."
issues <- searchAllHaskellIssues today interval
log I "Upserting issues into the database..."
upsertIssues issues
wait populateCategoriesAsync
log I "All repositories and issues successfully synchronized"

-- | This function takes a @Repo@ and updates its category field in the database.
syncCategories
Expand All @@ -73,22 +59,3 @@ syncCategories Repo{..} = do
categories <- getCabalCategories repoOwner repoName
updateRepoCategories repoOwner repoName categories
log I "Categories successfully updated"

-- | This function fetches all issues from the GitHub API and upserts them into the database.
syncIssues
:: forall env m.
( MonadUnliftIO m
, WithDb env m
, WithLog env m
, WithError m
)
=> Integer
-> m ()
syncIssues interval = do
log I "Starting synchronization of issues..."
today <- liftIO getToday
log I "Searching for all Haskell issues..."
issues <- searchAllHaskellIssues today interval
log I "Upserting issues into the database..."
upsertIssues issues
log I "Issues successfully synchronized"

0 comments on commit 5f29295

Please sign in to comment.