Eventually I found out: GitHub denies access if the User-Agent header is missing.
This works:
def http = new HTTPBuilder('https://api.github.com')
def response = http.get(path: '/users/qmetric',
headers: [(USER_AGENT): "Apache HTTPClient"])