コード例 #1
0
    def storyCreated(self, project, story, **kwargs):
        """ Called when a new ScrumDo story is created. This plugin creates a GitHub issue if the upload option is enabled. """

        if self._getExternalLink(story) != None:
            # Already uploaded
            return

        configuration = self.getConfiguration(project.slug)

        if not configuration.get('upload'):
            # Not configured to upload new stories.
            return

        repository = configuration.get('repository')
        logging.debug("Attempting to create GitHub issue for story %d" %
                      story.id)
        github = kwargs.get(
            "github",
            Github(username=configuration.get('username'),
                   api_token=configuration.get('password'),
                   requests_per_second=1))
        issue = github.issues.open(repository, story.summary, story.detail)
        link = ExternalStoryMapping(
            story=story,
            extra_slug=self.getSlug(),
            external_id=issue.number,
            external_url="https://github.com/%s/issues/#issue/%d" %
            (repository, issue.number))
        link.save()
        logging.info("GitHub issue #%d created for story %d" %
                     (issue.number, story.id))
コード例 #2
0
 def _initialUpload(self, project, configuration):
     configuration = self.getConfiguration(project.slug)
     github = Github(username=configuration.get('username'),
                     api_token=configuration.get('password'),
                     requests_per_second=1)
     for story in project.stories.all():
         self.storyCreated(project, story, github=github)
コード例 #3
0
    def storyStatusChange(self, project, story, **kwargs):
        logging.debug("GitHub issues::storyStatusChange")
        configuration = self.getConfiguration(project.slug)

        # The configuration view sets a download flag to true/false depending on user input.
        if not configuration.get("upload"):
            logging.debug("Not set to upload stories, aborting.")
            return

        link = self._getExternalLink(story)

        if link == None:
            logging.debug(
                "Story not associated with external story, aborting.")
            return
        # Grab the github client passed in kwargs, if none, create one.
        github = kwargs.get(
            "github",
            Github(username=configuration.get('username'),
                   api_token=configuration.get('password'),
                   requests_per_second=1))

        if story.status == Story.STATUS_DONE:
            github.issues.close(configuration.get('repository'),
                                link.external_id)
        else:
            # All other scrumdo statuses map to open on github issues.
            github.issues.reopen(configuration.get('repository'),
                                 link.external_id)
コード例 #4
0
    def storyUpdated(self, project, story, **kwargs):
        "Called when a story is updated in a project that this extra is associated with."
        logging.debug("GitHub issues::storyUpdated")
        configuration = self.getConfiguration(project.slug)

        # I think we should update stories if an external link exists, no matter how it got there.
        # # The configuration view sets a download flag to true/false depending on user input.
        # if not configuration.get("upload"):
        #   logging.debug("Not set to upload stories, aborting.")
        #   return

        link = self._getExternalLink(story)

        if link == None:
            logging.debug(
                "Story not associated with external story, aborting.")
            return

        # Grab the github client passed in kwargs, if none, create one.
        github = kwargs.get(
            "github",
            Github(username=configuration.get('username'),
                   api_token=configuration.get('password'),
                   requests_per_second=1))
        github.issues.edit(configuration.get('repository'), link.external_id,
                           story.summary, story.detail)
コード例 #5
0
    def pullProject(self, project):
        """ Pulls any new GitHub issues to Scrumdo, updates any existing
        Scrumdo stories that were associated with GitHub issues. """
        logging.debug("GitHubIssues::pullProject starting up.")
        configuration = self.getConfiguration(project.slug)

        # The configuration view sets a download flag to true/false depending on user input.
        if not configuration.get("download"):
            logging.debug("Not set to download stories, aborting.")
            return

        try:
            logging.debug("Retrieving remote issues")
            github = Github(username=configuration.get('username'),
                            api_token=configuration.get('password'),
                            requests_per_second=1)
            issues = github.issues.list(configuration.get('repository'),
                                        state="open")
        except:
            logging.warn(
                "Failed to retrieve remote GitHub issues for project %s" %
                project.slug)
            configuration["status"] = "Failed to load your GitHub issues"
            self.saveConfiguration(project.slug, configuration)
            return

        logging.debug("Retrieved %d GitHub issues" % len(issues))

        queue_stories = StoryQueue.objects.filter(project=project,
                                                  extra_slug=self.getSlug())
        logging.debug("%d stories already sitting in the story queue" %
                      len(queue_stories))
        project_stories = self._getStoriesInProjectAssociatedWithExtra(project)
        logging.debug(
            "%d stories in the project associated with GitHub issues" %
            len(project_stories))

        for issue in issues:
            story = self._getStory(issue.number, queue_stories,
                                   project_stories)
            if story == None:
                self._createStoryForIssue(issue, project,
                                          configuration.get('repository'))
            else:
                if story.summary != issue.title or story.detail != issue.body:
                    logging.debug("Updating story %d." % story.id)
                    story.summary = issue.title
                    story.detail = issue.body
                    story.save()

        configuration["status"] = "Syncronized with GitHub on " + str(
            datetime.date.today())
        logging.debug("pullProject complete, saving configuration.")
        self.saveConfiguration(project.slug, configuration)
コード例 #6
0
    def storyDeleted( self, project, external_id, **kwargs):
        """Called when a story is deleted in a project that this extra is associated with.  """
        configuration = self.getConfiguration( project.slug )

        if not configuration.get('delete'):
            return # Not configured to delete stories.

        repository = configuration.get('repository')
        logging.debug("Attempting to delete GitHub issue %s" % external_id)
        github = kwargs.get( "github", Github(username=configuration.get('username'), api_token=configuration.get('password'),requests_per_second=1) )
        issue = github.issues.close( repository, external_id )