예제 #1
0
파일: issue.py 프로젝트: publicscience/hive
 def reopen(self):
     self.open = True
     if self.linked():
         github.api().patch(self.linked_url(), data=json.dumps({'state': 'open'}))
     e = event.Event(type='reopened', author=user.current_user())
     self.events.append(e)
     self.save()
예제 #2
0
    def process(self, files):
        self.save()
        self.parse_mentions()

        # Create or update comment on GitHub if its issue is linked.
        if self.issue.linked():
            # Update
            if self.github_id:
                url = '/repos/' + self.issue.project.repo + '/issues/' + str(self.issue.github_id) + '/comments/' + str(self.github_id)
                resp = github.api().patch(url, data=json.dumps({'body':self.body}))
                if resp.status_code != 200:
                    raise Exception('Error updating comment on GitHub.')
            # Create
            else:
                url = '/repos/' + self.issue.project.repo + '/issues/' + str(self.issue.github_id) + '/comments'
                resp = github.api().post(url, data=json.dumps({'body':self.body}))
                if resp.status_code != 201:
                    raise Exception('Error creating comment on GitHub.')
                self.github_id = resp.json()['id']
        self.save()

        # Parse and create references to other issues.
        self.issue.parse_references(self.body)

        self.issue.project.process_attachments(files, self)

        if self not in self.issue.comments:
            self.issue.comments.append(self)
        self.issue.save()
예제 #3
0
파일: issue.py 프로젝트: publicscience/hive
 def close(self):
     self.open = False
     if self.linked():
         github.api().patch(self.linked_url(), data=json.dumps({'state': 'closed'}))
     e = event.Event(type='closed', author=user.current_user())
     self.events.append(e)
     self.save()
예제 #4
0
파일: issue.py 프로젝트: publicscience/hive
    def _sync_events(self):
        # Get events,and update them all.
        default_author = user.User.default()
        token = self.project.author.github_access
        ges = github.api(token=token).get(self.linked_url(end='/events')).json()
        for ge in ges:
            # Clean up redundant/outdated event.
            e = next((e_ for e_ in self.events if e_.github_id==ge['id']), 0)
            if e:
                self.events.remove(e)

            e = event.Event()

            e_author = user.User.objects(github_id=ge['actor']['id']).first()
            if not e_author:
                e_author = default_author

            e_updates = {
                    'github_id': ge['id'],
                    'created_at': datetime.strptime(ge['created_at'], '%Y-%m-%dT%H:%M:%SZ'),
                    'type': ge['event'],
                    'author': e_author,
                    'commit_id': ge['commit_id']
            }
            for k,v in e_updates.iteritems():
                setattr(e, k, v)
            self.events.append(e)
예제 #5
0
파일: issue.py 프로젝트: publicscience/hive
    def _sync_comments(self):
        # Get comments, and update them all.
        default_author = user.User.default()
        token = self.project.author.github_access
        gcs = github.api(token=token).get(self.linked_url(end='/comments')).json()
        for gc in gcs:
            # Clean up redundant/outdated comment.
            c = next((c_ for c_ in self.comments if c_.github_id==gc['id']), 0)
            if c:
                self.comments.remove(c)

            c = comment.Comment()

            c_author = user.User.objects(github_id=gc['user']['id']).first()
            if not c_author:
                c_author = default_author

            c_updates = {
                    'github_id': gc['id'],
                    'created_at': datetime.strptime(gc['created_at'], '%Y-%m-%dT%H:%M:%SZ'),
                    'updated_at': datetime.strptime(gc['updated_at'], '%Y-%m-%dT%H:%M:%SZ'),
                    'body': gc['body'],
                    'author': c_author,
                    'issue': self
            }
            for k,v in c_updates.iteritems():
                setattr(c, k, v)
            c.save()
            self.comments.append(c)
예제 #6
0
파일: issue.py 프로젝트: publicscience/hive
    def _sync_data(self, data=None):
        # Syncs issue data with its GitHub correlate (if it exists).
        # Optionally pass in data to update with.
        default_author = user.User.default()
        token = self.project.author.github_access

        if data is None:
            data = github.api(token=token).get(self.linked_url()).json()

        # Process data and apply it to the issue.
        open = True if data['state'] == 'open' else False
        labels = [label['name'] for label in data['labels']]
        author = user.User.objects(github_id=data['user']['id']).first()
        if not author:
            author = default_author

        updates = {
            'created_at': datetime.strptime(data['created_at'], '%Y-%m-%dT%H:%M:%SZ'),
            'updated_at': datetime.strptime(data['updated_at'], '%Y-%m-%dT%H:%M:%SZ'),
            'title': data['title'],
            'body': data['body'],
            'open': open,
            'labels': labels,
            'author': author
        }
        for k,v in updates.iteritems():
            setattr(self, k, v)
예제 #7
0
 def sync(self):
     if self.linked():
         token = self.author.github_access
         github_issues = github.api(token=token).get('/repos/'+self.repo+'/issues').json() + github.api(token=token).get('/repos/'+self.repo+'/issues', params={'state': 'closed'}).json()
         for gi in github_issues:
             i, created = issue.Issue.objects.get_or_create(github_id=gi['number'], project=self)
             if created:
                 self.issues.append(i)
             i.sync(data=gi)
         self.save()
예제 #8
0
파일: issue.py 프로젝트: publicscience/hive
    def push_to_github(self):
        # Update corresponding GitHub issue.
        if self.github_id:
            url = self.linked_url()
            resp = github.api().patch(url, data=json.dumps({
                'title': self.title,
                'body': self.body,
                'labels': self.labels
            }))
            if resp.status_code != 200:
                raise Exception('Error updating issue on GitHub.')

        # Create issue on GitHub if flag is present.
        elif '%github' in self.body:
            url = '/repos/'+self.project.repo+'/issues'
            resp = github.api().post(url, data=json.dumps({
                'title': self.title,
                'body': self.body,
                'labels': self.labels
            }))
            if resp.status_code != 201:
                raise Exception('Error creating issue on GitHub.')

            self.github_id = resp.json()['number']
예제 #9
0
 def ping_repo(self):
     token = self.author.github_access
     resp = github.api(token=token).get('/repos/'+self.repo)
     return resp.status_code == 200