-
Notifications
You must be signed in to change notification settings - Fork 194
Partial escape in query string to make search work again #321
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
base: master
Are you sure you want to change the base?
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
{-# LANGUAGE OverloadedStrings #-} | ||
module AllHaskellRepos where | ||
import Control.Monad(when) | ||
import Data.List(group, sort) | ||
import qualified Data.Text as T | ||
import qualified Data.Text.IO as T | ||
import qualified Data.Vector as V | ||
import Data.Time.Calendar(addDays, Day(..), showGregorian) | ||
import Data.Time.Clock(getCurrentTime, UTCTime(..)) | ||
import Data.Time.Format(parseTimeM, defaultTimeLocale, iso8601DateFormat) | ||
import Time.System(dateCurrent) | ||
import GitHub.Auth(Auth(..)) | ||
import GitHub.Endpoints.Search(searchRepos', SearchResult(..), EscapeItem(..), | ||
searchIssues') | ||
import GitHub.Data.Repos | ||
import GitHub.Data.Definitions | ||
import GitHub.Data.Name | ||
import GitHub.Data.URL | ||
import GitHub.Data.Options(SearchRepoMod(..), SearchRepoOptions(..), Language(..), | ||
License(..), StarsForksUpdated(..), SortDirection(..), | ||
searchRepoModToQueryString) | ||
import System.FilePath.Posix(FilePath) | ||
import Debug.Trace | ||
|
||
-- | A search query finds all Haskell libraries on github | ||
-- and updates two files of all packages/authors | ||
updateGithub :: [FilePath] -> IO () | ||
updateGithub [lastIntervalEnd, authorsCsv, packagesCsv] = do | ||
lastEnd <- T.readFile lastIntervalEnd -- first time: 2008-03-01 | ||
start <- parseTimeM True defaultTimeLocale (iso8601DateFormat Nothing) (T.unpack lastEnd) | ||
intervals pass start 10 -- stop after 10 queries | ||
a <- T.readFile authorsCsv | ||
T.writeFile authorsCsv (dups a) | ||
p <- T.readFile packagesCsv | ||
T.writeFile packagesCsv (dups p) | ||
where | ||
dups = T.unlines . map head . group . sort . T.lines | ||
-- Go through all github repos, by chosing small time intervals | ||
intervals :: String -> Day -> Int -> IO () | ||
intervals pass start i = do | ||
let newDate = addDays 10 start -- assuming less than 100 repos in 10 days | ||
|
||
-- Remember the last succesfully scanned interval | ||
-- (to update the list and continue when query timeout reached or query failed) | ||
T.writeFile lastIntervalEnd (T.pack (showGregorian newDate)) | ||
|
||
-- https://api.github.com/search/repositories?q=language:haskell+created:2009-01-01..2009-02-01&sort=stars&order=desc | ||
let query search = search { searchRepoOptionsLanguage = Just (Language "Haskell") | ||
, searchRepoOptionsSortBy = Just Stars | ||
, searchRepoOptionsOrder = Just SortDescending | ||
, searchRepoOptionsCreated = Just (start, newDate) | ||
} | ||
res <- searchRepos' (Just $ BasicAuth "user" "pass") (SearchRepoMod query) | ||
either (\_-> return ()) appendToCSV res | ||
-- putStrLn (show res) -- for debugging | ||
currentDate <- fmap utctDay getCurrentTime | ||
when (newDate < currentDate && i>0) (intervals pass newDate (i-1)) | ||
|
||
appendToCSV :: SearchResult Repo -> IO () | ||
appendToCSV res = do | ||
V.mapM_ extractFromRepo (searchResultResults res) | ||
where | ||
extractFromRepo r = do | ||
T.appendFile authorsCsv (untagName (simpleOwnerLogin (repoOwner r)) `T.append` "\n") | ||
T.appendFile packagesCsv (getUrl (repoHtmlUrl r) `T.append` "\n") | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ module GitHub.Endpoints.GitData.Trees ( | |
import GitHub.Data | ||
import GitHub.Internal.Prelude | ||
import GitHub.Request | ||
import qualified Network.HTTP.Types as W | ||
import Prelude () | ||
|
||
-- | A tree for a SHA1. | ||
|
@@ -56,4 +57,5 @@ nestedTree = nestedTree' Nothing | |
-- See <https://developer.github.com/v3/git/trees/#get-a-tree-recursively> | ||
nestedTreeR :: Name Owner -> Name Repo -> Name Tree -> Request k Tree | ||
nestedTreeR user repo sha = | ||
query ["repos", toPathPart user, toPathPart repo, "git", "trees", toPathPart sha] [("recursive", Just "1")] | ||
query ["repos", toPathPart user, toPathPart repo, "git", "trees", toPathPart sha] | ||
[("recursive", [W.QE "1"])] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 4 space indentation (tabular formatting doesn't apply here). |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,7 @@ module GitHub.Endpoints.Organizations.Teams ( | |
import GitHub.Data | ||
import GitHub.Internal.Prelude | ||
import GitHub.Request | ||
import qualified Network.HTTP.Types as W | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We use import Github.Request
import Prelude ()
import qualified Network.HTTP.Types as W There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok |
||
import Prelude () | ||
|
||
-- | List teams. List the teams of an Owner. | ||
|
@@ -133,7 +134,7 @@ deleteTeamR tid = | |
-- See <https://developer.github.com/v3/orgs/teams/#list-team-members> | ||
listTeamMembersR :: Id Team -> TeamMemberRole -> FetchCount -> Request 'RA (Vector SimpleUser) | ||
listTeamMembersR tid r = | ||
pagedQuery ["teams", toPathPart tid, "members"] [("role", Just r')] | ||
pagedQuery ["teams", toPathPart tid, "members"] [("role", [W.QE r'])] | ||
where | ||
r' = case r of | ||
TeamMemberRoleAll -> "all" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
orphan instance :/.
Could you make a PR to
http-types
so the instance is there. Alternatively inline code where instance is needed?I won't accept PR with orphan instance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I should have done this. But now it have wrapped the type in a newtype, because I don't want to go through the whole process of having the right http-types version in stackage.