示例#1
0
  def CreateComment(self, issue_number, source_issue_id,
                    googlecode_comment, project_name):
    """Creates a comment on a GitHub issue.

    Args:
      issue_number: The issue number.
      source_issue_id: The Google Code issue id.
      googlecode_comment: A GoogleCodeComment instance.
      project_name: The Google Code project name.

    Raises:
      issues.ServiceError: An error occurred creating the comment.
    """
    comment_url = "%s/%d/comments" % (self._github_issues_url, issue_number)
    comment = googlecode_comment.GetDescription()

    json_body = json.dumps({"body": comment})
    response, content = self._github_service.PerformPostRequest(
        comment_url, json_body)

    if not _CheckSuccessful(response):
      raise issues.ServiceError(
          "\nFailed to create issue comment (%s) for issue #%d\n%s" %
          (googlecode_comment.GetContent(), issue_number, content))
    time.sleep(self._comment_delay)
示例#2
0
  def CreateIssue(self, googlecode_issue):
    """Creates a GitHub issue.

    Args:
      googlecode_issue: An instance of GoogleCodeIssue

    Returns:
      The issue number of the new issue.

    Raises:
      issues.ServiceError: An error occurred creating the issue.
    """
    issue_title = googlecode_issue.GetTitle()
    issue = {
        "title": issue_title,
        "body": googlecode_issue.GetDescription(),
        "assignee": googlecode_issue.GetOwner(),
        "labels": googlecode_issue.GetLabels().append(googlecode_issue.GetStatus()),
    }
    response, content = self._github_service.PerformPostRequest(
        self._github_issues_url, json.dumps(issue))

    if not _CheckSuccessful(response):
      # Newline character at the beginning of the line to allows for in-place
      # updating of the counts of the issues and comments.
      raise issues.ServiceError("\nFailed to create issue: %s.\n%s" % (
          issue_title, content))

    return self._GetIssueNumber(content)
示例#3
0
    def CreateIssue(self, googlecode_issue):
        """Creates a GitHub issue.

    Args:
      googlecode_issue: An instance of GoogleCodeIssue

    Returns:
      The issue number of the new issue.

    Raises:
      issues.ServiceError: An error occurred creating the issue.
    """
        issue_title = googlecode_issue.GetTitle()
        # It is not possible to create a Google Code issue without a title, but you
        # can edit an issue to remove its title afterwards.
        if issue_title.isspace():
            issue_title = "<empty title>"
        issue = {
            "title": issue_title,
            "body": googlecode_issue.GetDescription(),
            "assignee": googlecode_issue.GetOwner(),
            "labels": googlecode_issue.GetLabels(),
        }
        response, content = self._github_service.PerformPostRequest(
            self._github_issues_url, json.dumps(issue))

        if not _CheckSuccessful(response):
            # Newline character at the beginning of the line to allows for in-place
            # updating of the counts of the issues and comments.
            raise issues.ServiceError(
                "\nFailed to create issue #%d '%s'.\n\n\n"
                "Response:\n%s\n\n\nContent:\n%s" %
                (googlecode_issue.GetId(), issue_title, response, content))

        return self._GetIssueNumber(content)
示例#4
0
    def CreateIssue(self, googlecode_issue):
        """Creates a GitHub issue.

    Args:
      googlecode_issue: An instance of GoogleCodeIssue

    Returns:
      The issue number of the new issue.

    Raises:
      issues.ServiceError: An error occurred creating the issue.
    """
        issue_title = googlecode_issue.GetTitle()
        # NOTE: Only users with "push" access can set labels for new issues. See:
        # https://developer.github.com/v3/issues/#create-an-issue
        issue = {
            "title": issue_title,
            "body": googlecode_issue.GetDescription(),
            "assignee": googlecode_issue.GetOwner(),
            "labels": googlecode_issue.GetLabels(),
        }
        response, content = self._github_service.PerformPostRequest(
            self._github_issues_url, json.dumps(issue))

        if not _CheckSuccessful(response):
            # Newline character at the beginning of the line to allows for in-place
            # updating of the counts of the issues and comments.
            raise issues.ServiceError(
                "\nFailed to create issue #%d '%s'.\n\n\n"
                "Response:\n%s\n\n\nContent:\n%s" %
                (googlecode_issue.GetId(), issue_title, response, content))

        return self._GetIssueNumber(content)
  def EditComment(self, googlecode_issue, googlecode_comment, comment_number):
    """Edits an existing comment."""
    comment_url = "%s/comments/%s" % (self._github_issues_url, comment_number)
    comment = googlecode_comment.GetDescription()

    json_body = json.dumps({"body": comment})
    response, content = self._github_service.PerformPostRequest(
        comment_url, json_body)

    if not _CheckSuccessful(response):
      raise issues.ServiceError(
          "\nFailed to edit comment with number #%d\n\n"
          "Response:\n%s\n\nContent:\n%s\n\n" %
          (comment_number, response, content))
    time.sleep(self._comment_delay)
示例#6
0
  def CloseIssue(self, issue_number):
    """Closes a GitHub issue.

    Args:
      issue_number: The issue number.

    Raises:
      issues.ServiceError: An error occurred closing the issue.
    """
    issue_url = "%s/%d" % (self._github_issues_url, issue_number)
    json_state = json.dumps({"state": "closed"})
    response, content = self._github_service.PerformPatchRequest(
        issue_url, json_state)
    if not _CheckSuccessful(response):
      raise issues.ServiceError("\nFailed to close issue #%s.\n%s" % (
          issue_number, content))
  def EditIssue(self, googlecode_issue, issue_number):
    """Edits an existing GitHub issue."""
    issue_title = googlecode_issue.GetTitle()
    issue = {
        "title": issue_title,
        "body": googlecode_issue.GetDescription(),
        "assignee": googlecode_issue.GetOwner(),
        "labels": googlecode_issue.GetLabels(),
    }
    response, content = self._github_service.PerformPatchRequest(
        self._github_issues_url + ("/%s" % issue_number), json.dumps(issue))

    if not _CheckSuccessful(response):
      # Newline character at the beginning of the line to allows for in-place
      # updating of the counts of the issues and comments.
      raise issues.ServiceError(
          "\nFailed to edit issue #%d '%s'.\n\n\n"
          "Response:\n%s\n\n\nContent:\n%s" % (
              googlecode_issue.GetId(), issue_title, response, content))
  def CreateComment(self, issue_number, googlecode_comment):
    """Creates a comment on a GitHub issue.

    Args:
      issue_number: The issue number on GitHub to post to.
      googlecode_comment: A GoogleCodeComment instance.

    Raises:
      issues.ServiceError: An error occurred creating the comment.
    """
    comment_url = "%s/%d/comments" % (self._github_issues_url, issue_number)
    comment = googlecode_comment.GetDescription()

    json_body = json.dumps({"body": comment})
    response, content = self._github_service.PerformPostRequest(
        comment_url, json_body)

    if not _CheckSuccessful(response):
      raise issues.ServiceError(
          "\nFailed to create comment for issue #%d\n\n"
          "Response:\n%s\n\nContent:\n%s\n\n" %
          (issue_number, response, content))
    time.sleep(self._comment_delay)