Exemple #1
0
 def __init__(self, ticket):
     self.project = CodeDoubanProject.get(ticket.project_id)
     self.proj_name = self.project.name
     self.ticket_id = ticket.ticket_number
     self.ticket = ticket
     self.pullreq = PullRequest.get_by_proj_and_ticket(
         self.project.id, self.ticket_id)
Exemple #2
0
 def add_related_project(self, repo_url):
     info = urlparse(repo_url)
     project_name = info.path.strip('/')
     from models.project import CodeDoubanProject
     prj = CodeDoubanProject.get_by_name(project_name)
     if prj not in self.related_projects:
         store.execute('insert into issue_related_projects '
                       '(issue_id, project_id) values(%s, %s)',
                       (self.issue_id, prj.id))
         store.commit()
    def test_new_project_issue_participant_count(self):
        app = TestApp(M.app)
        project_name = "project"
        project = CodeDoubanProject.add(project_name, owner_id="test1", summary="test", product="fire")
        issue = ProjectIssue.add("test", "test description", "test", project=project.id)
        resp = app.get(issue.url)

        assert resp.status_int == 200
        assert "Issues" in resp.body
        assert "<strong>1</strong> participant" in resp.text
        assert "<strong>1</strong> participants" not in resp.text
    def test_zero_vote_and_zero_comment_display(self):
        app = TestApp(M.app)
        project_name = "project"
        project = CodeDoubanProject.add(
            project_name, owner_id="test1", summary="test", product="fire")
        issue = ProjectIssue.add('test', 'test description', 'test',
                                 project=project.id)
        resp = app.get(project.url + "/issues/")

        assert resp.status_int == 200
        assert 'Issues' in resp.body
        assert '0 vote' not in resp.body
        assert '0 comment' not in resp.body
    def test_two_comments_display(self):
        app = TestApp(M.app)
        project_name = "project4"
        project = CodeDoubanProject.add(
            project_name, owner_id="test1", summary="test", product="fire")
        issue = ProjectIssue.add('test', 'test description', 'test',
                                 project=project.id)
        issue.add_comment('this is a comment', 'test')
        issue.add_comment('this is also a comment', 'test')
        resp = app.get(project.url + "/issues/")

        assert resp.status_int == 200
        assert "Issues" in resp.body
        assert "2 comments" in resp.body
    def test_two_votes_display(self):
        app = TestApp(M.app)
        project_name = "project3"
        project = CodeDoubanProject.add(
            project_name, owner_id="test1", summary="test", product="fire")
        issue = ProjectIssue.add('test', 'test description', 'test',
                                 project=project.id)
        issue.upvote_by_user('test1')
        issue.upvote_by_user('test2')
        resp = app.get(project.url + "/issues/")

        assert resp.status_int == 200
        assert "Issues" in resp.body
        assert "2 votes" in resp.body
Exemple #7
0
    def telchar(self, request):
        proj_id = self.proj_id
        user = request.user
        project = CodeDoubanProject.get(proj_id)
        url = TELCHAR_URL

        if project.is_owner(user):
            is_disable = request.get_form_var('close', '')
            if is_disable:
                hook = CodeDoubanHook.get_by_url(url)
                if hook:
                    hook.destroy()
                status = 0
            else:
                CodeDoubanHook.add(url, proj_id)
                status = 1
            return {'r': 0, 'status': status}
        return {'r': 1}
Exemple #8
0
def delete_tag(request):
    # FIXME: ugly
    if request.method == "POST":
        user = request.user
        if not user:
            return {'r': 0, 'msg': '未登录,请先登录'}
        tag_name = request.get_form_var('tag_name', '').decode('utf-8')
        tag_type = request.get_form_var('tag_type', '')
        tag_target_id = request.get_form_var('tag_target_id', '')

        if not tag_name:
            return {'r': 0, 'msg': 'tag不能为空'}
        try:
            tag_type, tag_target_id = int(tag_type), int(tag_target_id)
        except:
            return {'r': 0, 'msg': '错误的数据类型'}

        if tag_type == TAG_TYPE_PROJECT_ISSUE:
            target = CodeDoubanProject.get(tag_target_id)
        elif tag_type == TAG_TYPE_TEAM_ISSUE:
            target = Team.get(tag_target_id)
        else:
            return {'r': 0, 'msg': '错误的数据类型'}

        if not target.is_admin(user.name):
            return {'r': 0, 'msg': '没有操作权限'}

        tname = TagName.get_by_name_and_target_id(tag_name, tag_type, target.id)
        if not tname:
            return {'r': 0, 'msg': 'tag不存在'}

        tags = Tag.gets_by_tag_id(tname.id)
        for tag in tags:
            tag.delete()
        tname.delete()
        return {'r': 1, 'msg': '删除成功'}
Exemple #9
0
 def projects(self):
     from models.project import CodeDoubanProject
     return filter(None, [CodeDoubanProject.get(_)
                          for _ in self.project_ids])
Exemple #10
0
 def project(self):
     from models.project import CodeDoubanProject
     return CodeDoubanProject.get(self.target.project_id)
Exemple #11
0
 def related_projects(self):
     rs = store.execute('select project_id from issue_related_projects '
                        'where issue_id=%s', (self.issue_id,))
     prj_ids = [id for (id, ) in rs]
     from models.project import CodeDoubanProject
     return CodeDoubanProject.gets(prj_ids)
Exemple #12
0
from libs.permdir import get_repo_root
from libs.store import store
from models.project import CodeDoubanProject as Project
from models.pull import PullRequest
from models.ticket import Ticket

from tests.utils import clone

from local_config import DOMAIN

p1_name = "project1"
p1_id = None
p1_path = os.path.join(get_repo_root(), "%s.git" % p1_name)
shutil.rmtree(p1_path, ignore_errors=True)
p1 = Project.get_by_name(p1_name)
if p1:
    p1_id = p1.id
    p1.delete()

p2_name = "project2"
p2_id = None
p2_path = os.path.join(get_repo_root(), "%s.git" % p2_name)
shutil.rmtree(p2_path, ignore_errors=True)
p2 = Project.get_by_name(p2_name)
if p2:
    p2_id = p2.id
    p2.delete()

if p1_id:
    store.execute("delete from codedouban_ticket where project_id=%s", p1_id)
Exemple #13
0
 def projects(self):
     from models.project import CodeDoubanProject
     rs = ProjectGroup.gets(group_id=self.id)
     return filter(None, [CodeDoubanProject.get(r.project_id) for r in rs])
Exemple #14
0
 def get_by_proj_name_and_number(cls, proj_name, number):
     from models.project import CodeDoubanProject
     project = CodeDoubanProject.get_by_name(proj_name)
     project_issue = cls.get(project.id, number=number)
     issue_id = project_issue.issue_id
     return Issue.get_cached_issue(issue_id)
Exemple #15
0
 def proj_name(self):
     from models.project import CodeDoubanProject
     return CodeDoubanProject.get(self.project_id).name