module Network.Octohat.Members
( membersForOrganization
, teamsForOrganization
, membersForTeam
, reposForTeam
, addMemberToTeam
, addRepoToTeam
, deleteMemberFromTeam
, deleteTeamFromOrganization
, publicKeysForUser
, addTeamToOrganization
, organizations
, userForUsername
, repoForReponame
, addPublicKey
, resetPage
) where
import Network.Octohat.Internal
import Network.Octohat.Types
import qualified Data.Text as T
import Data.Monoid ((<>))
addTeamToOrganization :: TeamName
-> T.Text
-> TeamPermission
-> OrganizationName
-> GitHub Team
addTeamToOrganization (TeamName nameOfNewTeam) descOfTeam teamPerm (OrganizationName org) =
postRequestTo (composeEndpoint ["orgs", org, "teams"]) (TeamCreateRequest nameOfNewTeam descOfTeam teamPerm)
deleteTeamFromOrganization :: Integer
-> GitHub DidDelete
deleteTeamFromOrganization idOfTeam = deleteRequestTo (composeEndpoint ["teams", T.pack $ show idOfTeam])
membersForOrganization :: OrganizationName
-> GitHub [Member]
membersForOrganization (OrganizationName nameOfOrg) = getRequestPaginatedTo (composeEndpoint ["orgs", nameOfOrg, "members"])
membersForTeam :: Integer
-> GitHub [Member]
membersForTeam idOfTeam = getRequestPaginatedTo (composeEndpoint ["teams", T.pack $ show idOfTeam, "members"])
reposForTeam :: Integer
-> GitHub [Repo]
reposForTeam idOfTeam = getRequestPaginatedTo (composeEndpoint ["teams", T.pack $ show idOfTeam, "repos"])
teamsForOrganization :: OrganizationName
-> GitHub [Team]
teamsForOrganization (OrganizationName nameOfOrg) = getRequestPaginatedTo (composeEndpoint ["orgs", nameOfOrg, "teams"])
organizations :: GitHub [Organization]
organizations = getRequestPaginatedTo (composeEndpoint ["user", "orgs"])
addMemberToTeam :: T.Text
-> Integer
-> GitHub StatusInTeam
addMemberToTeam nameOfUser idOfTeam =
putRequestTo (composeEndpoint ["teams", T.pack $ show idOfTeam, "memberships", nameOfUser])
addRepoToTeam :: OrganizationName
-> T.Text
-> Integer
-> GitHub StatusInTeam
addRepoToTeam (OrganizationName nameOfOrg) nameOfRepo idOfTeam =
putRequestTo (composeEndpoint ["teams", T.pack $ show idOfTeam, "repos", nameOfOrg, nameOfRepo])
deleteMemberFromTeam :: T.Text
-> Integer
-> GitHub DidDelete
deleteMemberFromTeam nameOfUser idOfTeam =
deleteRequestTo (composeEndpoint ["teams", T.pack $ show idOfTeam, "memberships", nameOfUser])
publicKeysForUser :: T.Text
-> GitHub [PublicKey]
publicKeysForUser nameOfUser = getRequestPaginatedTo (composeEndpoint ["users", nameOfUser, "keys"])
userForUsername :: T.Text
-> GitHub Member
userForUsername username = getRequestTo (composeEndpoint ["users", username])
repoForReponame :: T.Text
-> T.Text
-> GitHub Repo
repoForReponame org repo = getRequestTo (composeEndpoint ["repos", org, repo])
addPublicKey :: T.Text
-> T.Text
-> GitHub PublicKey
addPublicKey newKey newTitle =
postRequestTo (composeEndpoint ["user", "keys"]) (AddPublicKeyRequest ("ssh-rsa " <> newKey) newTitle)