Esempio n. 1
0
def issue(title, body, name, context=None, state="open", since=None):
    item = "{0} {1}".format(name, context or "").strip()

    for issue in api.issues(state=state, since=since):
        checklist = github.Checklist(issue["body"])
        if item in checklist.items:
            return issue

    checklist = github.Checklist(body)
    checklist.add(item)
    data = {"title": title, "body": checklist.body, "labels": ["bot"]}
    return api.post("issues", data)
Esempio n. 2
0
def finish(publishing, ret, name, context, issue):
    if not publishing:
        return

    if not ret:
        comment = None
        result = "Completed"
    elif isinstance(ret, basestring):
        comment = "{0}: :link".format(ret)
        result = ret
    else:
        comment = "Task failed: :link"
        result = "Failed"

    duration = int(time.time() - publishing.start)
    sys.stdout.write("\n# Result: {0}\n# Duration: {1}s\n".format(
        result, duration))

    if issue:
        # Note that we check whether pass or fail ... this is because
        # the task is considered "done" until a human comes through and
        # triggers it again by unchecking the box.
        item = "{0} {1}".format(name, context or "").strip()
        checklist = github.Checklist(issue["body"])
        checklist.check(item, ret and "FAIL" or True)

        number = issue["number"]
        requests = [{
            "method": "POST",
            "resource": api.qualify("issues/{0}".format(number)),
            "data": {
                "title": issue["title"],
                "body": checklist.body
            }
        }]

        # Close the issue if it's not a pull request, successful, and only one task to do
        if "pull_request" not in issue and not ret and len(
                checklist.items) == 1:
            requests[0]["data"]["state"] = "closed"

        # Comment if there was a failure
        if comment:
            requests.insert(
                0, {
                    "method": "POST",
                    "resource": api.qualify(
                        "issues/{0}/comments".format(number)),
                    "data": {
                        "body": comment
                    }
                })

    else:
        requests = []

    publishing.status['github']['requests'] = requests
    publishing.status['github']['watches'] = None
    publishing.status['github']['onaborted'] = None
    publishing.flush()
Esempio n. 3
0
def issue(title, body, name, context=None):
    for issue in api.issues(state="open"):
        if issue["title"].endswith(title):
            return issue

    item = "{0} {1}".format(name, context or "").strip()
    checklist = github.Checklist(body)
    checklist.add(item)

    data = {"title": title, "body": checklist.body, "labels": ["bot"]}
    return api.post("issues", data)
Esempio n. 4
0
def finish(publishing, ret, name, context, issue):
    if not publishing:
        return

    if not ret:
        comment = None
    elif isinstance(ret, basestring):
        comment = "{0}: :link".format(ret)
    else:
        comment = "Task failed: :link"

    if issue:
        # Note that we check whether pass or fail ... this is because
        # the task is considered "done" until a human comes through and
        # triggers it again by unchecking the box.
        item = "{0} {1}".format(name, context or "").strip()
        checklist = github.Checklist(issue["body"])
        checklist.check(item)

        number = issue["number"]
        requests = [{
            "method": "POST",
            "resource": api.qualify("issues/{0}".format(number)),
            "data": {
                "title": issue["title"],
                "body": checklist.body
            }
        }]
        if comment:
            requests.append({
                "method":
                "POST",
                "resource":
                api.qualify("issues/{0}/comments".format(number)),
                "data": {
                    "body": comment
                }
            })
    else:
        requests = []

    publishing.status['github']['requests'] = requests
    publishing.status['github']['watches'] = None
    publishing.status['github']['onaborted'] = None
    publishing.flush()