示例#1
0
    def import_pull_requests(self, event, unit, repo_url, repo_name):
        pull_req = event.payload['pull_request']
        actor = pull_req['user']

        author_homepage = actor['html_url']
        author_id = str(actor['id'])
        author_name = str(actor['login'])
        pr_url = pull_req['html_url']
        date = pull_req['updated_at']
        state = pull_req['state']

        # Should title and body concatenated?
        title = pull_req['title']
        if title is None:
            title = ''
        body = pull_req['body']
        if body is None:
            body = ""

        # Repository information 
        head_repo = pull_req['head']['repo']
        head_repo_name = head_repo['full_name']
        head_repo_url = head_repo['html_url']
        # base_repo = pull_req['base']['repo']
        # base_repo_name = base_repo['full_name']
        # base_repo_url = base_repo['html_url']

        # verb is opened when action is opened and reopened
        verb = xapi_settings.VERB_OPENED
        evety_type = self.EVENT_TYPE_OPEN_PR
        action = event.payload['action']
        if action == self.ISSUE_STATUS_CLOSED:
            verb = xapi_settings.VERB_CLOSED
            evety_type = self.EVENT_TYPE_CLOSE_PR

        other_context_list = []
        # Import event type
        other_context_list.append(get_other_contextActivity(
            pr_url, 'Verb', evety_type, xapi_settings.get_verb_iri(verb)))
        # Repository url and name
        other_context_list.append(get_other_contextActivity(
            repo_url, 'Object', repo_name, xapi_settings.get_verb_iri(verb)))
        # Import head repository
        other_context_list.append(get_other_contextActivity(
            head_repo_url, 'Object', head_repo_name, xapi_settings.get_verb_iri(verb)))
        # Import the pull rquest message body
        # Title is required when user create issue, but body (message) is optional, and thus it is imported as additional data
        other_context_list.append(get_other_contextActivity(
            pr_url, 'Object', body, xapi_settings.get_verb_iri(verb)))
        
        if username_exists(author_id, unit, self.platform):
            # TODO: Is review correct object?
            user = get_user_from_screen_name(author_id, self.platform)
            insert_closedopen_object(user, pr_url, title, date, unit, self.platform, self.platform_url,
                                 xapi_settings.OBJECT_REVIEW, verb, parent_id = repo_url,
                                 obj_parent_type = xapi_settings.OBJECT_COLLECTION,
                                 other_contexts = other_context_list)
示例#2
0
    def import_issues(self, event, unit, repo_url, repo_name):
        issue = event.payload['issue']
        actor = issue['user']

        author_id = str(actor['id'])
        author_name = str(actor['login'])
        author_homepage = actor['html_url']
        issue_url = issue['html_url']
        date = issue['updated_at']
        title = issue['title']
        body = issue['body']
        if title is None:
            title = ''
        if body is None:
            body = ''

        # verb is opened when action is opened and reopened
        verb = xapi_settings.VERB_OPENED
        evety_type = self.EVENT_TYPE_OPEN_ISSUE
        action = event.payload['action']
        if action == self.ISSUE_STATUS_CLOSED:
            verb = xapi_settings.VERB_CLOSED
            evety_type = self.EVENT_TYPE_CLOSE_ISSUE
        elif action == self.ISSUE_STATUS_REOPENED:
            verb = xapi_settings.VERB_OPENED
            evety_type = self.EVENT_TYPE_REOPEN_ISSUE

        # print 'action: %s ..... verb: %s' % (action, verb)

        other_context_list = []
        # Import event type
        other_context_list.append(get_other_contextActivity(
            issue_url, 'Verb', evety_type, xapi_settings.get_verb_iri(verb)))
        # Repository url and name
        other_context_list.append(get_other_contextActivity(
            repo_url, 'Object', repo_name, xapi_settings.get_verb_iri(verb)))
        # Issue url and title 
        other_context_list.append(get_other_contextActivity(
            issue_url, 'Object', body, xapi_settings.get_verb_iri(verb)))

        # print 'issue url" %s ' % issue_url
        # print 'verb: %s ' % verb
        if username_exists(author_id, unit, self.platform):
            user = get_user_from_screen_name(author_id, self.platform)
            insert_closedopen_object(user, issue_url, title, date, unit, self.platform, self.platform_url,
                                 xapi_settings.OBJECT_NOTE, verb, parent_id = repo_url,
                                 obj_parent_type = xapi_settings.OBJECT_COLLECTION,
                                 other_contexts = other_context_list, platform_id = event.id)

        # Return the issue number for assignees & assigner data import
        # return issue['number']
        return issue['events_url'], issue_url, title
示例#3
0
    def import_issue_comments(self, event, unit, repo_url, repo_name):
        iss_comment = event.payload['comment']
        issue = event.payload['issue']
        actor = iss_comment['user']

        author_homepage = actor['html_url']
        author_id = str(actor['id'])
        author_name = str(actor['login'])
        issue_url = issue['html_url']
        iss_comment_url = iss_comment['html_url']
        date = iss_comment['updated_at']

        issue_title = issue['title']
        body = iss_comment['body']
        if issue_title is None:
            issue_title = ""
        if body is None:
            body = ""

        other_context_list = []
        # Import event type
        other_context_list.append(get_other_contextActivity(
            iss_comment_url, 'Verb', event.type, 
            xapi_settings.get_verb_iri(xapi_settings.VERB_COMMENTED)))
        # Issue url and title
        other_context_list.append(get_other_contextActivity(
            issue_url, 'Object', issue_title, 
            xapi_settings.get_verb_iri(xapi_settings.VERB_COMMENTED)))
        # Repository url and name
        other_context_list.append(get_other_contextActivity(
            repo_url, 'Object', repo_name, 
            xapi_settings.get_verb_iri(xapi_settings.VERB_COMMENTED)))
        
        if username_exists(author_id, unit, self.platform):
            user = get_user_from_screen_name(author_id, self.platform)
            insert_comment(user, issue_url, iss_comment_url, body, date, unit, self.platform, self.platform_url,
                parent_user_external = issue_title, other_contexts = other_context_list)
示例#4
0
    def import_commit_comments(self, event, unit, repo_url, repo_name, repo):
        com_comment = event.payload['comment']
        actor = com_comment['user']

        author_homepage = actor['html_url']
        author_id = str(actor['id'])
        author_name = str(actor['login'])
        com_comment_url = com_comment['html_url']
        date = com_comment['updated_at']
        body = com_comment['body']
        if body is None:
            body = ""

        commit = repo.get_commit(sha = com_comment['commit_id'])
        commit_url = commit.html_url
        commit_message = commit.commit.message
        if commit_message is None:
            commit_message = ""

        other_context_list = []
        # Import event type
        other_context_list.append(get_other_contextActivity(
            com_comment_url, 'Verb', event.type, 
            xapi_settings.get_verb_iri(xapi_settings.VERB_COMMENTED)))
        # Commit url and message (title)
        other_context_list.append(get_other_contextActivity(
            commit_url, 'Object', commit_message, 
            xapi_settings.get_verb_iri(xapi_settings.VERB_COMMENTED)))
        # Repository url and name
        other_context_list.append(get_other_contextActivity(
            repo_url, 'Object', repo_name, 
            xapi_settings.get_verb_iri(xapi_settings.VERB_COMMENTED)))
        
        if username_exists(author_id, unit, self.platform):
            user = get_user_from_screen_name(author_id, self.platform)
            insert_comment(user, commit_url, com_comment_url, body, date, unit, self.platform, self.platform_url,
                parent_user_external = commit_message, other_contexts = other_context_list)
示例#5
0
    def import_files(self, file, unit, repo_url, repo_name, author_details, commit_details, commit_date):
        author_id = author_details['author_id']
        author_name = author_details['author_name']
        author_homepage = author_details['author_homepage']
        commit_title = commit_details['title']
        commit_url = commit_details['url']
        commit_sha = commit_details['sha']
        file_url = file.blob_url

        verb = xapi_settings.VERB_ADDED
        activity = self.EVENT_TYPE_ADD_FILE;
        if file.status == self.FILE_STATUS_MODIFIED:
            verb = xapi_settings.VERB_UPDATED
            activity = self.EVENT_TYPE_UPDATE_FILE
        elif file.status == self.FILE_STATUS_REMOVED:
            verb = xapi_settings.VERB_REMOVED
            activity = self.EVENT_TYPE_REMOVE_FILE

        # Diffs between the current code and previous code
        patch = file.patch
        if file.patch is None:
            patch = ""

        other_context_list = []
        # Import file status
        other_context_list.append(get_other_contextActivity(
            file_url, 'Verb', activity, xapi_settings.get_verb_iri(verb)))
        # Commit url and title
        other_context_list.append(get_other_contextActivity(
            commit_url, 'Object', commit_title, xapi_settings.get_verb_iri(verb)))
        # Repository url and name
        other_context_list.append(get_other_contextActivity(
            repo_url, 'Object', repo_name, xapi_settings.get_verb_iri(verb)))
        # File name
        other_context_list.append(get_other_contextActivity(
            file_url, 'Object', file.filename, xapi_settings.get_verb_iri(verb)))
        # Total number of lines changed 
        other_context_list.append(get_other_contextActivity(
            file_url, 'Object', str(file.changes), xapi_settings.get_verb_iri(verb)))
        # Additions
        other_context_list.append(get_other_contextActivity(
            file_url, 'Object', str(file.additions), xapi_settings.get_verb_iri(verb)))
        # Deletions
        other_context_list.append(get_other_contextActivity(
            file_url, 'Object', str(file.deletions), xapi_settings.get_verb_iri(verb)))

        if username_exists(author_id, unit, self.platform):
            user = get_user_from_screen_name(author_id, self.platform)
            insert_file(user, commit_url, file_url, patch, commit_date, unit, self.platform, self.platform_url, verb, 
                other_contexts = other_context_list)
示例#6
0
    def import_TrelloActivity(self, feed, unit):
        #User needs to sign up username and board (board can be left out but is needed)
        print 'Beginning Trello import!'

        for action in list(feed):
            #We need to connect this with our user profile somewhere when they initially auth
            u_id = action['idMemberCreator']
            author = action['memberCreator']['username']
            type = action['type']  #commentCard, updateCard, createList,etc
            data = action['data']
            date = action['date']
            board_name = data['board']['name']

            # print 'got action type: %s' % (type)

            #Get all 'commented' verb actions
            if (type == self.ACTION_TYPE_COMMENT_CARD):
                target_obj_id = self.create_card_url(data)
                comment_from_uid = u_id
                comment_from_name = author
                comment_message = data['text']
                comment_id = target_obj_id + '/' + action['id']
                card_name = data['card']['name']

                if username_exists(comment_from_uid, unit, self.platform):
                    # Create "other" contextActivity object to store original activity in xAPI
                    card_details = self.TrelloCient.fetch_json(
                        '/cards/' + data['card']['id'])
                    context = get_other_contextActivity(
                        card_details['shortUrl'], 'Verb', type,
                        xapi_settings.get_verb_iri(
                            xapi_settings.VERB_COMMENTED))
                    context2 = get_other_contextActivity(
                        card_details['shortUrl'], 'Object',
                        data['card']['name'],
                        xapi_settings.get_verb_iri(
                            xapi_settings.VERB_COMMENTED))
                    other_context_list = [context, context2]

                    user = get_user_from_screen_name(comment_from_uid,
                                                     self.platform)
                    insert_comment(user,
                                   target_obj_id,
                                   comment_id,
                                   comment_message,
                                   date,
                                   unit,
                                   self.platform,
                                   self.platform_url,
                                   parent_user_external=card_name,
                                   other_contexts=other_context_list)

            if (type == self.ACTION_TYPE_CREATE_CARD):
                object_id = self.create_card_url(data) + '/' + action['id']
                card_name = data['card']['name']
                parent_id = self.create_list_url(data)

                if username_exists(u_id, unit, self.platform):
                    # Create "other" contextActivity object to store original activity in xAPI
                    card_details = self.TrelloCient.fetch_json(
                        '/cards/' + data['card']['id'])
                    context = get_other_contextActivity(
                        card_details['shortUrl'], 'Verb', type,
                        xapi_settings.get_verb_iri(xapi_settings.VERB_CREATED))
                    context2 = get_other_contextActivity(
                        card_details['shortUrl'], 'Object',
                        data['list']['name'],
                        xapi_settings.get_verb_iri(xapi_settings.VERB_CREATED))
                    other_context_list = [context, context2]
                    usr_dict = ClaUserUtil.get_user_details_by_smid(
                        u_id, self.platform)
                    user = get_user_from_screen_name(u_id, self.platform)

                    insert_task(user,
                                object_id,
                                card_name,
                                date,
                                unit,
                                self.platform,
                                self.platform_url,
                                parent_id=parent_id,
                                other_contexts=other_context_list)

            #Get all 'add' verbs (you tecnically aren't *creating* an attachment on a card so....)
            if (type in [
                    self.ACTION_TYPE_ADD_ATTACHMENT_TO_CARD,
                    self.ACTION_TYPE_ADD_CHECKLIST_TO_CARD,
                    self.ACTION_TYPE_ADD_MEMBER_TO_CARD
            ]):
                user = get_user_from_screen_name(u_id, self.platform)
                if user is None:
                    continue

                card_url = self.create_card_url(data)

                # Create "other" contextActivity object to store original activity in xAPI
                other_context_list = []
                card_details = self.TrelloCient.fetch_json('/cards/' +
                                                           data['card']['id'])
                context = get_other_contextActivity(
                    card_details['shortUrl'], 'Verb', type,
                    xapi_settings.get_verb_iri(xapi_settings.VERB_ADDED))
                other_context_list.append(context)
                context2 = get_other_contextActivity(
                    card_details['shortUrl'], 'Object', data['card']['name'],
                    xapi_settings.get_verb_iri(xapi_settings.VERB_ADDED))
                other_context_list = [context, context2]

                if type == self.ACTION_TYPE_ADD_ATTACHMENT_TO_CARD:

                    attachment = data['attachment']
                    attachment_id = card_url + '/' + data['attachment']['id']
                    attachment_data = attachment['name']
                    object_type = xapi_settings.OBJECT_FILE
                    parent_user_external = '%sc/%s' % (self.platform_url,
                                                       card_url)
                    other_context_list.append(
                        get_other_contextActivity(
                            card_details['shortUrl'], 'Object',
                            attachment['url'],
                            xapi_settings.get_verb_iri(
                                xapi_settings.VERB_ADDED)))

                    insert_added_object(
                        user,
                        card_url,
                        attachment_id,
                        attachment_data,
                        date,
                        unit,
                        self.platform,
                        self.platform_url,
                        object_type,
                        parent_user_external=parent_user_external,
                        other_contexts=other_context_list)

                if type == self.ACTION_TYPE_ADD_MEMBER_TO_CARD:  #or 'addMemberToBoard':

                    object_id = card_url + '/' + action['member']['id']
                    object_data = action['member']['username']
                    object_type = xapi_settings.OBJECT_PERSON
                    parent_user_external = '%sc/%s' % (self.platform_url,
                                                       card_url)

                    insert_added_object(
                        user,
                        card_url,
                        object_id,
                        object_data,
                        date,
                        unit,
                        self.platform,
                        self.platform_url,
                        object_type,
                        parent_user_external=parent_user_external,
                        other_contexts=other_context_list)

                if type == self.ACTION_TYPE_ADD_CHECKLIST_TO_CARD:

                    object_id = card_url + '/' + data['checklist']['id']
                    object_data = None
                    checklist_items = None
                    object_type = xapi_settings.OBJECT_COLLECTION
                    parent_user_external = '%sc/%s' % (self.platform_url,
                                                       card_url)

                    #get checklist contents
                    try:
                        checklist = self.TrelloCient.fetch_json(
                            '/checklists/' + data['checklist']['id'], )
                        checklist_items = checklist['checkItems']
                    except Exception:
                        print 'Could not retrieve checklist..'
                        continue

                    object_data = data['checklist']['name']
                    for item in checklist_items:
                        # items are stored individually in other contextActivities
                        other_context_list.append(
                            get_other_contextActivity(
                                card_details['shortUrl'], 'Object',
                                item['name'],
                                xapi_settings.get_verb_iri(
                                    xapi_settings.VERB_ADDED)))

                    insert_added_object(
                        user,
                        card_url,
                        object_id,
                        object_data,
                        date,
                        unit,
                        self.platform,
                        self.platform_url,
                        object_type,
                        parent_user_external=parent_user_external,
                        other_contexts=other_context_list)

            if (type in [
                    self.ACTION_TYPE_UPDATE_CHECKITEM_STATE_ON_CARD,
                    self.ACTION_TYPE_UPDATE_CARD
            ]):
                user = get_user_from_screen_name(u_id, self.platform)
                if user is None:
                    continue

                card_details = self.TrelloCient.fetch_json('/cards/' +
                                                           data['card']['id'])
                #many checklist items will be bugged - we require webhooks!

                if type == self.ACTION_TYPE_UPDATE_CHECKITEM_STATE_ON_CARD:
                    # Import check item ID & its state
                    # Use action ID as an object ID to avoid ID conflict.
                    object_id = self.create_card_url(data) + '/' + action['id']
                    obj_val = data['checkItem']['state']

                    # Create "other" contextActivity object to store original activity in xAPI
                    other_context_list = []
                    other_context_list.append(
                        get_other_contextActivity(
                            self.create_checklist_url(data), 'Verb', type,
                            xapi_settings.get_verb_iri(
                                xapi_settings.VERB_UPDATED)))
                    other_context_list.append(
                        get_other_contextActivity(
                            card_details['shortUrl'], 'Object',
                            data['checkItem']['name'],
                            xapi_settings.get_verb_iri(
                                xapi_settings.OBJECT_CHECKLIST_ITEM)))
                    other_context_list.append(
                        get_other_contextActivity(
                            card_details['shortUrl'], 'Object',
                            data['card']['name'],
                            xapi_settings.get_verb_iri(
                                xapi_settings.VERB_UPDATED)))

                    insert_updated_object(
                        user,
                        object_id,
                        obj_val,
                        date,
                        unit,
                        self.platform,
                        self.platform_url,
                        xapi_settings.OBJECT_CHECKLIST_ITEM,
                        parent_id=self.create_checklist_url(data),
                        obj_parent_type=xapi_settings.OBJECT_CHECKLIST,
                        other_contexts=other_context_list)

                #up to us to figure out what's being updated
                if type == self.ACTION_TYPE_UPDATE_CARD:

                    #Get and store the values that were changed, usually it's only one
                    #TODO: Handle support for multiple changes, if that's possible
                    try:
                        change = [
                            changed_value for changed_value in data['old']
                        ]
                    except Exception:
                        print 'Error occurred getting changes...'

                    # Use action ID as an object ID to avoid ID conflict.
                    object_id = self.create_card_url(data) + '/' + action['id']

                    if change[0] == 'pos':
                        # When user moves card in the same list (change order)

                        object_text = data['card']['name']
                        # object_text = 'Change order of card: %s to %s' % (data['old']['pos'], data['card']['pos'])
                        # object_text = card_name + object_text
                        other_context_list = []
                        other_context_list.append(
                            get_other_contextActivity(
                                card_details['shortUrl'], 'Verb',
                                self.ACTION_TYPE_MOVE_CARD,
                                xapi_settings.get_verb_iri(
                                    xapi_settings.VERB_UPDATED)))
                        other_context_list.append(
                            get_other_contextActivity(
                                card_details['shortUrl'], 'Object',
                                self.MESSAGE_CARD_POSITION_CHANGED,
                                xapi_settings.get_verb_iri(
                                    xapi_settings.VERB_UPDATED)))
                        other_context_list.append(
                            get_other_contextActivity(
                                card_details['shortUrl'], 'Object',
                                str(data['old']['pos']),
                                xapi_settings.get_verb_iri(
                                    xapi_settings.VERB_UPDATED)))
                        other_context_list.append(
                            get_other_contextActivity(
                                card_details['shortUrl'], 'Object',
                                str(data['card']['pos']),
                                xapi_settings.get_verb_iri(
                                    xapi_settings.VERB_UPDATED)))

                        insert_updated_object(
                            user,
                            object_id,
                            object_text,
                            date,
                            unit,
                            self.platform,
                            self.platform_url,
                            xapi_settings.OBJECT_TASK,
                            parent_id=self.create_list_url(data),
                            obj_parent_type=xapi_settings.OBJECT_COLLECTION,
                            other_contexts=other_context_list)

                    else:
                        # When user moves card from a list to another
                        if data.has_key('listBefore'):
                            object_text = data['card']['name']
                            # object_text = 'from %s to %s' % (data['listBefore']['name'], data['listAfter']['name'])
                            # object_text = card_name + object_text

                            other_context_list = []
                            other_context_list.append(
                                get_other_contextActivity(
                                    card_details['shortUrl'], 'Verb',
                                    self.ACTION_TYPE_MOVE_CARD,
                                    xapi_settings.get_verb_iri(
                                        xapi_settings.VERB_UPDATED)))
                            other_context_list.append(
                                get_other_contextActivity(
                                    card_details['shortUrl'], 'Object',
                                    data['listBefore']['name'],
                                    xapi_settings.get_verb_iri(
                                        xapi_settings.VERB_UPDATED)))
                            other_context_list.append(
                                get_other_contextActivity(
                                    card_details['shortUrl'], 'Object',
                                    data['listAfter']['name'],
                                    xapi_settings.get_verb_iri(
                                        xapi_settings.VERB_UPDATED)))

                            insert_updated_object(
                                user,
                                object_id,
                                object_text,
                                date,
                                unit,
                                self.platform,
                                self.platform_url,
                                xapi_settings.OBJECT_TASK,
                                parent_id=self.create_card_url(data),
                                obj_parent_type=xapi_settings.
                                OBJECT_COLLECTION,
                                other_contexts=other_context_list)

                        # When user closes (archives)/opens card
                        elif data['old'][change[0]] is False or data['old'][
                                change[0]] is True:
                            verb = xapi_settings.VERB_CLOSED
                            verb_iri = xapi_settings.get_verb_iri(verb)
                            action_type = self.ACTION_TYPE_CLOSE_CARD
                            object_text = data['card']['name']

                            # When card is opened
                            if data['old'][change[0]] is True:
                                verb = xapi_settings.VERB_OPENED
                                verb_iri = xapi_settings.get_verb_iri(verb)
                                action_type = self.ACTION_TYPE_OPEN_CARD

                            other_context_list = []
                            other_context_list.append(
                                get_other_contextActivity(
                                    card_details['shortUrl'], 'Verb',
                                    action_type, verb_iri))
                            other_context_list.append(
                                get_other_contextActivity(
                                    card_details['shortUrl'], 'Object',
                                    data['list']['name'], verb_iri))

                            insert_closedopen_object(
                                user,
                                object_id,
                                object_text,
                                date,
                                unit,
                                self.platform,
                                self.platform_url,
                                xapi_settings.OBJECT_TASK,
                                verb,
                                parent_id=self.create_list_url(data),
                                obj_parent_type=xapi_settings.
                                OBJECT_COLLECTION,
                                other_contexts=other_context_list)
示例#7
0
    def import_commits(self, commit, unit, repo_url, repo_name):
        author_id = ''
        author_name = ''
        date = ''
        author_homepage = ''
        if commit.author is None or commit.author.id == '':
            # Note: What is the difference between author and committer?
            # 
            # The author is the person who originally wrote the work,
            # whereas the committer is the person who last applied the work. 
            # So, if you send in a patch to a project and one of the core members applies the patch, 
            # both of you get credit --- you as the author and the core member as the committer.
            print "commit.committer is null.url = " + commit.html_url
            #author = commit.author.name
            #email = commit.author.email
            author_id = commit.committer.id
            author_name = commit.committer.login
            author_homepage = commit.committer.html_url
            date = commit.commit.committer.date
        else:
            author_id = commit.author.id
            author_name = commit.author.login
            author_homepage = commit.author.html_url
            date = commit.commit.author.date

        # ID is all numbers, and thus needs to be converted to string
        author_id = str(author_id)
        # Rare case but committer name does not exist in some cases 
        if not username_exists(author_id, unit, self.platform):
            # commit.commit.author does not have the element "login" or "id"
            author_id = commit.commit.author.name
            author_name = commit.commit.author.name
            date = commit.commit.author.date

        # ID is all numbers, and thus needs to be converted to string
        author_id = str(author_id)
        author_name = str(author_name)
        commit_title = commit.commit.message
        commit_url = commit.html_url
        commit_sha = commit.sha

        # Don't process when user does not exist
        if not username_exists(author_id, unit, self.platform):
            return

        # create other context activity value
        # print 'Commit changes :%d, adds: %d, dels: %d' % (commit.stats.total, commit.stats.additions, commit.stats.deletions)
        total_list = []
        total_list.append(str(commit.stats.total))
        total_list.append(str(commit.stats.additions))
        total_list.append(str(commit.stats.deletions))
        filename_list = []
        additions_list = []
        deletions_list = []
        for file in commit.files:
            filename_list.append(file.filename)
            additions_list.append(str(file.additions))
            deletions_list.append(str(file.deletions))

        other_context_list = []
        # Import event type
        other_context_list.append(get_other_contextActivity(
            commit_url, 'Verb', self.EVENT_TYPE_COMMIT, 
            xapi_settings.get_verb_iri(xapi_settings.VERB_CREATED)))
        # Repository url and name
        other_context_list.append(get_other_contextActivity(
            repo_url, 'Object', repo_name,
            xapi_settings.get_verb_iri(xapi_settings.VERB_CREATED)))
        # Total number of changes, additions and deletions
        other_context_list.append(get_other_contextActivity(
            commit_url, 'Object', ','.join(total_list),
            xapi_settings.get_verb_iri(xapi_settings.VERB_CREATED)))
        # Commttied file names
        other_context_list.append(get_other_contextActivity(
            commit_url, 'Object', ','.join(filename_list),
            xapi_settings.get_verb_iri(xapi_settings.VERB_CREATED)))
        # Additions of each file
        other_context_list.append(get_other_contextActivity(
            commit_url, 'Object', ','.join(additions_list),
            xapi_settings.get_verb_iri(xapi_settings.VERB_CREATED)))
        # Deletions of each file
        other_context_list.append(get_other_contextActivity(
            commit_url, 'Object', ','.join(deletions_list),
            xapi_settings.get_verb_iri(xapi_settings.VERB_CREATED)))

        user = get_user_from_screen_name(author_id, self.platform)
        insert_commit(user, repo_url, commit_url, commit_title, date, unit, self.platform, self.platform_url, 
            other_contexts = other_context_list)

        author_details = {'author_id': author_id, 'author_name': author_name, 'author_homepage': author_homepage}
        commit_details = {'title': commit_title, 'url': commit_url, 'sha': commit_sha}
        # All committed files are inserted into DB
        for file in commit.files:
            self.import_files(file, unit, repo_url, repo_name, author_details, commit_details, date)
示例#8
0
    def import_issue_activities(self, event, unit, issue_list, repo_url, repo_name, repo, token):
        ### TODO: user PyGithub if possible.
        #         It seems that assignees and assigner returned via get_events() are wrong, 
        #         so not used at the moment.
        # for issue_number in issue_number_list:
        #     count = 0
            # issue = repo.get_issue(issue_number)
            # issue_events = issue.get_events().get_page(count)

            # while True:
            #     for event in issue_events:
            #         # Import assignees and assigner
            #         # print 'event.event === ' + event.event
            #         if event.event == self.ISSUE_EVENT_ASSIGNED:
            #             # Import assigner and assignees
            #             self.import_assingee_assigner(event, unit, issue, repo_url, repo_name)

            #     count = count + 1
            #     issue_events = issue.get_events().get_page(count)
            #     temp = list(issue_events)
            #     if len(temp) == 0:
            #         #Break from while
            #         break;
        
        for issue in issue_list:
            url = issue['issue_event_url'] + '?per_page=%d&access_token=%s' % (self.per_page, token)
            # print url
            req = urllib2.Request(url)
            response = urllib2.urlopen(req)
            issue_events = json.load(response)
            for issue_event in issue_events:
                if issue_event['event'] != self.ISSUE_EVENT_ASSIGNED:
                    continue

                event_url = issue_event['url']
                assignee = issue_event['assignee']
                assigner = issue_event['assigner']
                issue_url = issue['issue_html_url']
                issue_title = issue['issue_title']

                event_id = issue_event['id']
                assigner_id = str(assigner['id'])
                assigner_name = str(assigner['login'])
                assigner_url = assigner['html_url']

                assignee_id = str(assignee['id'])
                assignee_name = str(assignee['login'])
                assignee_url = assignee['html_url']
                date = issue_event['created_at']
                object_type = xapi_settings.OBJECT_PERSON
                
                other_context_list = []
                # Import event type
                other_context_list.append(get_other_contextActivity(
                    issue_url, 'Verb', self.EVENT_TYPE_ASSIGN_MEMBER, 
                    xapi_settings.get_verb_iri(xapi_settings.VERB_ADDED)))
                # Issue url and title
                other_context_list.append(get_other_contextActivity(
                    issue_url, 'Object', issue_title, 
                    xapi_settings.get_verb_iri(xapi_settings.VERB_ADDED)))
                # Repository url and name
                other_context_list.append(get_other_contextActivity(
                    repo_url, 'Object', repo_name, 
                    xapi_settings.get_verb_iri(xapi_settings.VERB_ADDED)))

                # When both assignee and assigner exist in the CLA toolkit, import data.
                if username_exists(assigner_id, unit, self.platform) and username_exists(assignee_id, unit, self.platform):
                    user = get_user_from_screen_name(assigner_id, self.platform)
                    insert_added_object(user, issue_url, event_url, assignee_name, date, unit, self.platform, self.platform_url,
                                        object_type, parent_user_external = issue_title, 
                                        other_contexts = other_context_list)