Ejemplo n.º 1
0
def assign(request):
    if request.method == 'POST':
        assignForm = AssignBugForm(request.POST)
        if assignForm.is_valid():
            bug = get_object_or_404(Bug, pk=assignForm.cleaned_data['bug_id'])
            bug.status = Bug.STATUS_ASSIGNED
            bug.resolver = User.objects.get(pk=assignForm.cleaned_data['user'])
            bug.original = None
            bug.save()
            # HAY QUE GUARDAR EN LOS COMENTARIOS EL CAMBIO DE STATUS
            c = Comment()
            c.content_type = ContentType.objects.get(app_label="bugs",
                                                     model="bug")
            c.object_pk = bug.pk
            c.site = Site.objects.get(id=settings.SITE_ID)
            c.comment = '{0} has assigned this bug to {1}. Its status has change to {2}'.format(
                request.user.username, bug.resolver.username,
                bug.get_status_display())
            c.save()
            return HttpResponseRedirect('/bugs/browse/{0}/{1}/{2}'.format(
                bug.component.application.id, bug.component.id, bug.id))
        else:
            messages.error(request,
                           "An error occur while trying to assign the bug.")
            return HttpResponseRedirect(reverse('BTS_home'))
    else:
        return Http404()
Ejemplo n.º 2
0
 def test_comment_post_save(self):
     content_type = ContentType.objects.get(model='issue')
     comment = Comment()
     comment.user_name = self.user.username
     comment.user_email = self.user.email
     comment.content_type = content_type
     comment.object_pk = 1
     comment.comment = "This is a test comment"
     comment.site = Site.objects.get(id=settings.SITE_ID)
     comment.save()
     print comment.comment
Ejemplo n.º 3
0
 def test_notify_on_comment(self):
     # post some comment
     comment = Comment()
     content_type = ContentType.objects.get(model='issue')
     comment = Comment()
     comment.user_name = 'somebody'
     comment.user_email = '*****@*****.**'
     comment.content_type = content_type
     comment.object_pk = 1
     comment.comment = "This is a test comment"
     comment.site = Site.objects.get(id=settings.SITE_ID)
     comment.save()
     
     self.assertEquals(len(mail.outbox), 3)        
     self.check_outbox(self.recipient_list, "DjTracker: [unittest-project]: New Comment on Issue #1 by somebody", comment.comment)        
Ejemplo n.º 4
0
def create_comment(oldcomment):
    current_site = Site.objects.get(id=settings.SITE_ID)
    content_type = ContentType.objects.get(app_label='blog', model='post')
    fields = oldcomment['fields']
    comment = Comment()
    comment.comment  = fields['comment']
    comment.ip_address  = fields['ip_address']
    comment.is_public  = fields['is_public']
    comment.is_removed  = fields['is_removed']
    comment.object_pk  = fields['object_pk']
    comment.submit_date  = fields['submit_date']
    comment.user  = None
    comment.user_email  = fields['user_email']
    comment.user_name  = fields['user_name']
    comment.user_url  = fields['user_url']
    comment.content_type  = content_type
    comment.site  = current_site
    comment.save()
Ejemplo n.º 5
0
def process_comment(request, commentform, post):
    try:
        comment = Comment.objects.get(id=commentform.cleaned_data.get('id', None))
    except Comment.DoesNotExist:
        comment = Comment()
    comment.content_object = post
    comment.site = Site.objects.get_current()
    comment.user = request.user
    try:
        profile = UserProfile.objects.get(user = request.user)
        comment.user_url = profile.get_absolute_url()
    except UserProfile.DoesNotExist:
        pass
    comment.comment = strip_tags(commentform.cleaned_data['comment'])
    comment.submit_date = datetime.datetime.now()
    comment.ip_address = request.META['REMOTE_ADDR']
    comment.is_public = True
    comment.is_removed = False
    comment.save()
    return comment
Ejemplo n.º 6
0
    def parse_repo(self, project):
        starting_commit = project.svn_repo_commit
        client = pysvn.Client()
        client.set_interactive(False)
        client.set_default_username(project.svn_repo_username)
        client.set_default_password(project.svn_repo_password)
        commits = client.log(
            project.svn_repo_url,
            revision_start=pysvn.Revision(pysvn.opt_revision_kind.number,
                                          int(starting_commit)),
            revision_end=pysvn.Revision(pysvn.opt_revision_kind.head))

        match_string = re.compile('Fixes #[\d]+')
        issue_matches = []
        for x in commits:
            for message in match_string.findall(x.data['message']):
                issue_matches.append(x)

        number_string = re.compile('\d+')
        closed_status = models.Status.objects.get(slug="closed")
        for x in issue_matches:
            for y in number_string.findall(x.data['message']):
                try:
                    issue = models.Issue.objects.get(id=y)
                    if issue.status is closed_status:
                        continue
                except ObjectDoesNotExist:
                    continue

                issue.status = closed_status
                issue.save()
                comment = Comment()
                comment.user_name = "vcs_bot"
                comment.user_email = "*****@*****.**"
                comment.content_type = self.content_type
                comment.object_pk = issue.id
                comment.comment = x.data['message']
                comment.site = Site.objects.get(id=settings.SITE_ID)
                comment.save()
                project.git_repo_commit = x.data['revision'].number
                project.save()
Ejemplo n.º 7
0
def update_status(request, bug_id):
    bug = get_object_or_404(Bug, pk=bug_id)
    if request.method == 'POST':
        f = UpdateBugStatusForm(request.POST, bug=bug)
        if f.is_valid():
            if not (request.user == bug.resolver or
                    (bug.status != Bug.STATUS_ASSIGNED
                     and request.user.has_perm("users.gatekeeper"))):
                return Http404(
                    "You don't have privileges to change the status of this bug."
                )
            resolver = (get_object_or_404(User, pk=f.cleaned_data['resolver'])
                        if f.cleaned_data['resolver'] else request.user)
            original = (get_object_or_404(Bug, pk=f.cleaned_data['original'])
                        if f.cleaned_data['original'] else None)
            resolution = f.cleaned_data['resolution']
            if bug.update_status(status=f.cleaned_data['status'],
                                 resolver=resolver,
                                 original=original,
                                 resolution=resolution):
                bug.save()
                c = Comment()
                c.content_type = ContentType.objects.get(app_label="bugs",
                                                         model="bug")
                c.object_pk = bug.pk
                c.site = Site.objects.get(id=settings.SITE_ID)
                c.comment = '{0} has changed the status to {1}'.format(
                    request.user.username, bug.get_status_display())
                c.save()
                messages.success(request,
                                 "The status has been updated successfully.")
                return HttpResponseRedirect('/bugs/browse/{0}/{1}/{2}'.format(
                    bug.component.application.id, bug.component.id, bug.id))
    else:
        f = UpdateBugStatusForm(bug=bug)
    return render_to_response('bugs/detail.html', {
        'bug': bug,
        'update_form': f
    },
                              context_instance=RequestContext(request))
Ejemplo n.º 8
0
    def parse_repo(self, project):
        starting_commit = project.svn_repo_commit
        client = pysvn.Client()
        client.set_interactive(False)
        client.set_default_username(project.svn_repo_username)
        client.set_default_password(project.svn_repo_password)
        commits = client.log(project.svn_repo_url,
           revision_start=pysvn.Revision(pysvn.opt_revision_kind.number, int(starting_commit)),
           revision_end=pysvn.Revision(pysvn.opt_revision_kind.head))

        match_string = re.compile('Fixes #[\d]+')
        issue_matches = []
        for x in commits:
            for message in match_string.findall(x.data['message']):
                issue_matches.append(x)

        number_string = re.compile('\d+')
        closed_status = models.Status.objects.get(slug="closed")
        for x in issue_matches:
            for y in number_string.findall(x.data['message']):
                try:
                    issue = models.Issue.objects.get(id=y)
                    if issue.status is closed_status:
                        continue
                except ObjectDoesNotExist:
                    continue

                issue.status=closed_status
                issue.save()
                comment = Comment()
                comment.user_name = "vcs_bot"
                comment.user_email = "*****@*****.**"
                comment.content_type = self.content_type
                comment.object_pk = issue.id
                comment.comment = x.data['message']
                comment.site = Site.objects.get(id=settings.SITE_ID)
                comment.save()
                project.git_repo_commit = x.data['revision'].number
                project.save()
Ejemplo n.º 9
0
def process_comment(request, commentform, post):
    print commentform.cleaned_data
    try:
        comment = Comment.objects.get(
            id=commentform.cleaned_data.get('id', None))
    except Comment.DoesNotExist:
        comment = Comment()
    comment.content_object = post
    comment.site = Site.objects.get_current()
    comment.user = request.user
    try:
        profile = UserProfile.objects.get(user=request.user)
        comment.user_url = profile.get_absolute_url()
    except UserProfile.DoesNotExist:
        pass
    comment.comment = strip_tags(commentform.cleaned_data['comment'])
    comment.submit_date = datetime.datetime.now()
    comment.ip_address = request.META['REMOTE_ADDR']
    comment.is_public = True
    comment.is_removed = False
    comment.save()
    return comment
Ejemplo n.º 10
0
    def parse_repo(self, project):
        repo = git.Repo(project.git_repo_path)
        starting_commit = project.git_repo_commit
        commits = repo.commits()
        for x in commits:
            if starting_commit == x.id:
                starting_commit = x
        index = commits.index(starting_commit)
        commits = commits[:index]
        match_string = re.compile('Fixes #[\d]+')
        issue_matches = []
        for x in commits:
            for message in match_string.findall(x.message):
                issue_matches.append(x)

        number_string = re.compile('\d+')
        closed_status = models.Status.objects.get(slug="closed")
        for x in issue_matches:
            for y in number_string.findall(x.message):
                try:
                    issue = models.Issue.objects.get(id=y)
                    if issue.status is closed_status:
                        continue
                except ObjectDoesNotExist:
                    continue

                issue.status = closed_status
                issue.save()
                comment = Comment()
                comment.user_name = "vcs_bot"
                comment.user_email = "*****@*****.**"
                comment.content_type = self.content_type
                comment.object_pk = issue.id
                comment.comment = x.message
                comment.site = Site.objects.get(id=settings.SITE_ID)
                comment.save()
                project.git_repo_commit = x.id
                project.save()
Ejemplo n.º 11
0
    def parse_repo(self, project):
        repo = git.Repo(project.git_repo_path)
        starting_commit = project.git_repo_commit
        commits = repo.commits()
        for x in commits:
            if starting_commit == x.id:
                starting_commit = x
        index = commits.index(starting_commit)
        commits = commits[:index]
        match_string = re.compile('Fixes #[\d]+')
        issue_matches = []
        for x in commits:
            for message in match_string.findall(x.message):
                issue_matches.append(x)

        number_string = re.compile('\d+')
        closed_status = models.Status.objects.get(slug="closed")
        for x in issue_matches:
            for y in number_string.findall(x.message):
                try:
                    issue = models.Issue.objects.get(id=y)
                    if issue.status is closed_status:
                        continue
                except ObjectDoesNotExist:
                    continue

                issue.status=closed_status
                issue.save()
                comment = Comment()
                comment.user_name = "vcs_bot"
                comment.user_email = "*****@*****.**"
                comment.content_type = self.content_type
                comment.object_pk = issue.id
                comment.comment = x.message
                comment.site = Site.objects.get(id=settings.SITE_ID)
                comment.save()
                project.git_repo_commit = x.id
                project.save()
Ejemplo n.º 12
0
    def parse_message(self, message, raw_data):
        ## Get project slug
        match = re.search("\[[\w-]+\]", message['subject'])
        project_slug = match.group().lstrip('[').rstrip(']')

        ## Get email address
        #print message['from']
        match = re.search(r'[a-zA-Z0-9+_\-\.]+@[0-9a-zA-Z]*.[a-zA-Z]+',
                               message['from'])
        #print match.group()
        email_addy = match.group()
        ## Get Issue Number (if exists)
        match = re.search("Issue #[\d]+", message['subject'])
        if match:
            issue_string = match.group()
            issue_num = issue_string.lstrip("Issue #")
            issue_title = message['subject'][match.end():].lstrip(" - ")
        else:
            issue_num = None
            match = re.search("\[[\w-]+\]", message['subject'])
            issue_title = message['subject'][match.end():]
            issue_title =  issue_title.lstrip(": ")

        ## Get our django objects
        try:
            project = models.Project.objects.get(slug=project_slug)
        except ObjectDoesNotExist:
            return

        try:
            user = User.objects.get(email=email_addy)
            can_comment = utils.check_permissions('comment', user, project)
        except ObjectDoesNotExist:
            can_comment = project.allow_anon_comment
            user = None

        try:
            issue = models.Issue.objects.get(id=issue_num)
        except ObjectDoesNotExist:
            issue = None

        body = raw_data[message.startofbody:]
        content_type = ContentType.objects.get(model='issue')

        #print can_comment
        if can_comment:
            if issue is not None:
                comment = Comment()
                if user is not None:
                    comment.user_name = user.username
                    comment.user_email = user.email
                else:
                    comment.user_name = email_addy
                    comment.user_email = email_addy

                comment.content_type = content_type
                comment.object_pk = issue.id
                comment.comment = body
                comment.site = Site.objects.get(id=settings.SITE_ID)
                comment.save()
            else:
                issue = models.Issue()
                issue.name = issue_title
                issue.project = project
                issue.description = body
                status = models.Status.objects.get(id=1)
                priority = models.Priority.objects.get(id=1)
                issue_type = models.IssueType.objects.get(id=1)
                issue.status = status
                issue.priority = priority
                issue.issue_type = issue_type
                issue.save()