query repositoryIDByName($name: String!) {
    me {
        repository(name: $name) {
            id
        }
    }
}

query repositoryIDByUser($username: String!, $name: String!) {
    user(username: $username) {
        repository(name: $name) {
            id
        }
    }
}

query listArtifacts($name: String!) {
    me {
        repository(name: $name) {
            ...artifacts
        }
    }
}

query listArtifactsByUser($username: String!, $name: String!) {
    user(username: $username) {
        repository(name: $name) {
            ...artifacts
        }
    }
}

fragment artifacts on Repository {
    references {
        results {
            name
            artifacts {
                results {
                    id
                    filename
                }
            }
        }
    }
}

query repositoryByName($name: String!) {
    me {
        repository(name: $name) {
            ...repository
        }
    }
}

query repositoryByUser($username: String!, $name: String!) {
    user(username: $username) {
        repository(name: $name) {
            ...repository
        }
    }
}

fragment repository on Repository {
    name
    description
    visibility
    references {
        results {
            name
        }
    }
    log {
        results {
            shortId
            author {
                name
                email
                time
            }
            message
        }
    }
}

query repositories($cursor: Cursor) {
    repositories(cursor: $cursor) {
        ...repos
    }
}

query repositoriesByUser($username: String!, $cursor: Cursor) {
    user(username: $username) {
        repositories(cursor: $cursor) {
            ...repos
        }
    }
}

fragment repos on RepositoryCursor {
    results {
        name
        description
        visibility
        owner {
          canonicalName
        }
    }
    cursor
}

query sshSettings {
    version {
        settings {
            sshUser
        }
    }
}

query repoNames {
    repositories {
        results {
            name
        }
    }
}

query revsByRepoName($name: String!) {
    me {
        repository(name: $name) {
            ...revs
        }
    }
}

query revsByUser($username: String!, $name: String!) {
    user(username: $username) {
        repository(name: $name) {
            ...revs
        }
    }
}

fragment revs on Repository {
    references {
        results {
            name
        }
    }
}

query aclByRepoName($name: String!) {
    me {
        repository(name: $name) {
            acls {
                results {
                    id
                    created
                    entity {
                        canonicalName
                    }
                    mode
                }
            }
        }
    }
}

query userWebhooks {
    userWebhooks {
        results {
            id
            url
        }
    }
}

mutation uploadArtifact($repoId: Int!, $revspec: String!, $file: Upload!) {
    uploadArtifact(repoId: $repoId, revspec: $revspec, file: $file) {
        filename
    }
}

mutation deleteArtifact($id: Int!) {
    deleteArtifact(id: $id) {
        filename
    }
}

mutation createRepository(
    $name: String!
    $visibility: Visibility!
    $description: String!
    $cloneUrl: String
) {
    createRepository(
        name: $name
        visibility: $visibility
        description: $description
        cloneUrl: $cloneUrl
    ) {
        owner {
            canonicalName
        }
        name
    }
}

mutation deleteRepository($id: Int!) {
    deleteRepository(id: $id) {
        name
    }
}

mutation updateACL($repoId: Int!, $mode: AccessMode!, $entity: ID!) {
    updateACL(repoId: $repoId, mode: $mode, entity: $entity) {
        entity {
            canonicalName
        }
    }
}

mutation deleteACL($id: Int!) {
    deleteACL(id: $id) {
        entity {
            canonicalName
        }
        repository {
            name
        }
    }
}

mutation deleteUserWebhook($id: Int!) {
    deleteUserWebhook(id: $id) {
        id
    }
}

mutation createUserWebhook($config: UserWebhookInput!) {
    createUserWebhook(config: $config) {
        id
    }
}

mutation updateRepository($id: Int!, $input: RepoInput!) {
    updateRepository(id: $id, input: $input) {
        name
    }
}
