Blame tests/test_progit_lib_git.py

Pierre-Yves Chibon a945ba
# -*- coding: utf-8 -*-
Pierre-Yves Chibon a945ba
Pierre-Yves Chibon a945ba
"""
Pierre-Yves Chibon a945ba
 (c) 2015 - Copyright Red Hat Inc
Pierre-Yves Chibon a945ba
Pierre-Yves Chibon a945ba
 Authors:
Pierre-Yves Chibon a945ba
   Pierre-Yves Chibon <pingou@pingoured.fr></pingou@pingoured.fr>
Pierre-Yves Chibon a945ba
Pierre-Yves Chibon a945ba
"""
Pierre-Yves Chibon a945ba
Pierre-Yves Chibon a945ba
__requires__ = ['SQLAlchemy >= 0.8']
Pierre-Yves Chibon a945ba
import pkg_resources
Pierre-Yves Chibon a945ba
Pierre-Yves Chibon c009bb
import json
Pierre-Yves Chibon a945ba
import unittest
Pierre-Yves Chibon a945ba
import shutil
Pierre-Yves Chibon a945ba
import sys
Pierre-Yves Chibon a945ba
import os
Pierre-Yves Chibon a945ba
Pierre-Yves Chibon 024459
import pygit2
Pierre-Yves Chibon a945ba
from mock import patch
Pierre-Yves Chibon a945ba
Pierre-Yves Chibon a945ba
sys.path.insert(0, os.path.join(os.path.dirname(
Pierre-Yves Chibon a945ba
    os.path.abspath(__file__)), '..'))
Pierre-Yves Chibon a945ba
Pierre-Yves Chibon a945ba
import progit.lib.git
Pierre-Yves Chibon a945ba
import tests
Pierre-Yves Chibon a945ba
Pierre-Yves Chibon a945ba
Pierre-Yves Chibon a945ba
class ProgitLibGittests(tests.Modeltests):
Pierre-Yves Chibon a945ba
    """ Tests for progit.lib.git """
Pierre-Yves Chibon a945ba
Pierre-Yves Chibon a945ba
    def test_write_gitolite_acls(self):
Pierre-Yves Chibon a945ba
        """ Test the write_gitolite_acls function of progit.lib.git. """
Pierre-Yves Chibon a945ba
        tests.create_projects(self.session)
Pierre-Yves Chibon a945ba
Pierre-Yves Chibon ead0df
        repo = progit.lib.get_project(self.session, 'test')
Pierre-Yves Chibon ead0df
        # Add an user to a project
Pierre-Yves Chibon ead0df
        msg = progit.lib.add_user_to_project(
Pierre-Yves Chibon ead0df
            session=self.session,
Pierre-Yves Chibon ead0df
            project=repo,
Pierre-Yves Chibon ead0df
            user='foo',
Pierre-Yves Chibon ead0df
        )
Pierre-Yves Chibon ead0df
        self.session.commit()
Pierre-Yves Chibon ead0df
        self.assertEqual(msg, 'User added')
Pierre-Yves Chibon ead0df
        # Add a forked project
Pierre-Yves Chibon ead0df
        item = progit.lib.model.Project(
Pierre-Yves Chibon ead0df
            user_id=1,  # pingou
Pierre-Yves Chibon ead0df
            name='test3',
Pierre-Yves Chibon ead0df
            description='test project #2',
Pierre-Yves Chibon ead0df
            parent_id=1
Pierre-Yves Chibon ead0df
        )
Pierre-Yves Chibon ead0df
        self.session.add(item)
Pierre-Yves Chibon ead0df
        self.session.commit()
Pierre-Yves Chibon ead0df
Pierre-Yves Chibon 6e1ebb
        outputconf = os.path.join(tests.HERE, 'test_gitolite.conf')
Pierre-Yves Chibon a945ba
Pierre-Yves Chibon a945ba
        progit.lib.git.write_gitolite_acls(self.session, outputconf)
Pierre-Yves Chibon a945ba
Pierre-Yves Chibon a945ba
        self.assertTrue(os.path.exists(outputconf))
Pierre-Yves Chibon a945ba
Pierre-Yves Chibon a945ba
        with open(outputconf) as stream:
Pierre-Yves Chibon a945ba
            data = stream.read()
Pierre-Yves Chibon a945ba
Pierre-Yves Chibon ead0df
        exp = """repo test
Pierre-Yves Chibon ead0df
  R   = @all
Pierre-Yves Chibon ead0df
  RW+ = pingou
Pierre-Yves Chibon ead0df
  RW+ = foo
Pierre-Yves Chibon ead0df
Pierre-Yves Chibon ead0df
repo docs/test
Pierre-Yves Chibon ead0df
  R   = @all
Pierre-Yves Chibon ead0df
  RW+ = pingou
Pierre-Yves Chibon ead0df
  RW+ = foo
Pierre-Yves Chibon ead0df
Pierre-Yves Chibon ead0df
repo tickets/test
Pierre-Yves Chibon ead0df
  R   = @all
Pierre-Yves Chibon ead0df
  RW+ = pingou
Pierre-Yves Chibon ead0df
  RW+ = foo
Pierre-Yves Chibon ead0df
Pierre-Yves Chibon ead0df
repo test2
Pierre-Yves Chibon ead0df
  R   = @all
Pierre-Yves Chibon ead0df
  RW+ = pingou
Pierre-Yves Chibon ead0df
Pierre-Yves Chibon ead0df
repo docs/test2
Pierre-Yves Chibon ead0df
  R   = @all
Pierre-Yves Chibon ead0df
  RW+ = pingou
Pierre-Yves Chibon ead0df
Pierre-Yves Chibon ead0df
repo tickets/test2
Pierre-Yves Chibon ead0df
  R   = @all
Pierre-Yves Chibon ead0df
  RW+ = pingou
Pierre-Yves Chibon ead0df
Pierre-Yves Chibon ead0df
repo forks/pingou/test3
Pierre-Yves Chibon ead0df
  R   = @all
Pierre-Yves Chibon ead0df
  RW+ = pingou
Pierre-Yves Chibon ead0df
Pierre-Yves Chibon ead0df
repo docs/pingou/test3
Pierre-Yves Chibon ead0df
  R   = @all
Pierre-Yves Chibon ead0df
  RW+ = pingou
Pierre-Yves Chibon ead0df
Pierre-Yves Chibon ead0df
repo tickets/pingou/test3
Pierre-Yves Chibon ead0df
  R   = @all
Pierre-Yves Chibon ead0df
  RW+ = pingou
Pierre-Yves Chibon ead0df
Pierre-Yves Chibon ead0df
"""
Pierre-Yves Chibon ead0df
        self.assertEqual(data, exp)
Pierre-Yves Chibon a945ba
Pierre-Yves Chibon 22e4bd
        os.unlink(outputconf)
Pierre-Yves Chibon 22e4bd
        self.assertFalse(os.path.exists(outputconf))
Pierre-Yves Chibon a945ba
Pierre-Yves Chibon 024459
    def test_commit_to_patch(self):
Pierre-Yves Chibon 024459
        """ Test the commit_to_patch function of progit.lib.git. """
Pierre-Yves Chibon 024459
        # Create a git repo to play with
Pierre-Yves Chibon 6e1ebb
        self.gitrepo = os.path.join(tests.HERE, 'test_repo.git')
Pierre-Yves Chibon 024459
        os.makedirs(self.gitrepo)
Pierre-Yves Chibon 024459
        repo = pygit2.init_repository(self.gitrepo)
Pierre-Yves Chibon 024459
Pierre-Yves Chibon 024459
        # Create a file in that git repo
Pierre-Yves Chibon 024459
        with open(os.path.join(self.gitrepo, 'sources'), 'w') as stream:
Pierre-Yves Chibon 024459
            stream.write('foo\n bar')
Pierre-Yves Chibon 024459
        repo.index.add('sources')
Pierre-Yves Chibon 024459
        repo.index.write()
Pierre-Yves Chibon 024459
Pierre-Yves Chibon 024459
        # Commits the files added
Pierre-Yves Chibon 024459
        tree = repo.index.write_tree()
Pierre-Yves Chibon 024459
        author = pygit2.Signature(
Pierre-Yves Chibon 024459
            'Alice Author', 'alice@authors.tld')
Pierre-Yves Chibon 024459
        committer = pygit2.Signature(
Pierre-Yves Chibon 024459
            'Cecil Committer', 'cecil@committers.tld')
Pierre-Yves Chibon 024459
        repo.create_commit(
Pierre-Yves Chibon 024459
            'refs/heads/master',  # the name of the reference to update
Pierre-Yves Chibon 024459
            author,
Pierre-Yves Chibon 024459
            committer,
Pierre-Yves Chibon 024459
            'Add sources file for testing',
Pierre-Yves Chibon 024459
            # binary string representing the tree object ID
Pierre-Yves Chibon 024459
            tree,
Pierre-Yves Chibon 024459
            # list of binary strings representing parents of the new commit
Pierre-Yves Chibon 024459
            []
Pierre-Yves Chibon 024459
        )
Pierre-Yves Chibon 024459
Pierre-Yves Chibon 024459
        first_commit = repo.revparse_single('HEAD')
Pierre-Yves Chibon 024459
Pierre-Yves Chibon 024459
        # Edit the sources file again
Pierre-Yves Chibon 024459
        with open(os.path.join(self.gitrepo, 'sources'), 'w') as stream:
Pierre-Yves Chibon 024459
            stream.write('foo\n bar\nbaz\n boose')
Pierre-Yves Chibon 024459
        repo.index.add('sources')
Pierre-Yves Chibon 024459
        repo.index.write()
Pierre-Yves Chibon 024459
Pierre-Yves Chibon 024459
        # Commits the files added
Pierre-Yves Chibon 024459
        tree = repo.index.write_tree()
Pierre-Yves Chibon 024459
        author = pygit2.Signature(
Pierre-Yves Chibon 024459
            'Alice Author', 'alice@authors.tld')
Pierre-Yves Chibon 024459
        committer = pygit2.Signature(
Pierre-Yves Chibon 024459
            'Cecil Committer', 'cecil@committers.tld')
Pierre-Yves Chibon 024459
        repo.create_commit(
Pierre-Yves Chibon 024459
            'refs/heads/master',  # the name of the reference to update
Pierre-Yves Chibon 024459
            author,
Pierre-Yves Chibon 024459
            committer,
Pierre-Yves Chibon 024459
            'Add baz and boose to the sources\n\n There are more objects to '
Pierre-Yves Chibon 024459
            'consider',
Pierre-Yves Chibon 024459
            # binary string representing the tree object ID
Pierre-Yves Chibon 024459
            tree,
Pierre-Yves Chibon 024459
            # list of binary strings representing parents of the new commit
Pierre-Yves Chibon 024459
            [first_commit.oid.hex]
Pierre-Yves Chibon 024459
        )
Pierre-Yves Chibon 024459
Pierre-Yves Chibon 024459
        second_commit = repo.revparse_single('HEAD')
Pierre-Yves Chibon 024459
Pierre-Yves Chibon 024459
        # Generate a patch for 2 commits
Pierre-Yves Chibon 024459
        patch = progit.lib.git.commit_to_patch(
Pierre-Yves Chibon 024459
            repo, [first_commit, second_commit])
Pierre-Yves Chibon 024459
        exp = """Mon Sep 17 00:00:00 2001
Pierre-Yves Chibon 024459
From: Alice Author <alice@authors.tld></alice@authors.tld>
Pierre-Yves Chibon 024459
Subject: [PATCH 1/2] Add sources file for testing
Pierre-Yves Chibon 024459
Pierre-Yves Chibon 024459
Pierre-Yves Chibon 024459
---
Pierre-Yves Chibon 024459
Pierre-Yves Chibon 024459
diff --git a/sources b/sources
Pierre-Yves Chibon 024459
new file mode 100644
Pierre-Yves Chibon 024459
index 0000000..9f44358
Pierre-Yves Chibon 024459
--- /dev/null
Pierre-Yves Chibon 024459
+++ b/sources
Pierre-Yves Chibon 024459
@@ -0,0 +1,2 @@
Pierre-Yves Chibon 024459
+foo
Pierre-Yves Chibon 024459
+ bar
Pierre-Yves Chibon 024459
\ No newline at end of file
Pierre-Yves Chibon 024459
Pierre-Yves Chibon 024459
Mon Sep 17 00:00:00 2001
Pierre-Yves Chibon 024459
From: Alice Author <alice@authors.tld></alice@authors.tld>
Pierre-Yves Chibon 024459
Subject: [PATCH 2/2] Add baz and boose to the sources
Pierre-Yves Chibon 024459
Pierre-Yves Chibon 024459
Pierre-Yves Chibon 024459
 There are more objects to consider
Pierre-Yves Chibon 024459
---
Pierre-Yves Chibon 024459
Pierre-Yves Chibon 024459
diff --git a/sources b/sources
Pierre-Yves Chibon 024459
index 9f44358..2a552bb 100644
Pierre-Yves Chibon 024459
--- a/sources
Pierre-Yves Chibon 024459
+++ b/sources
Pierre-Yves Chibon 024459
@@ -1,2 +1,4 @@
Pierre-Yves Chibon 024459
 foo
Pierre-Yves Chibon 024459
- bar
Pierre-Yves Chibon 024459
\ No newline at end of file
Pierre-Yves Chibon 024459
+ bar
Pierre-Yves Chibon 024459
+baz
Pierre-Yves Chibon 024459
+ boose
Pierre-Yves Chibon 024459
\ No newline at end of file
Pierre-Yves Chibon 024459
Pierre-Yves Chibon 024459
"""
Pierre-Yves Chibon 024459
        npatch = []
Pierre-Yves Chibon 024459
        for row in patch.split('\n'):
Pierre-Yves Chibon 024459
            if row.startswith('Date:'):
Pierre-Yves Chibon 024459
                continue
Pierre-Yves Chibon 024459
            if row.startswith('From '):
Pierre-Yves Chibon 024459
                row = row.split(' ', 2)[2]
Pierre-Yves Chibon 024459
            npatch.append(row)
Pierre-Yves Chibon 024459
Pierre-Yves Chibon 024459
        patch = '\n'.join(npatch)
Pierre-Yves Chibon 024459
        self.assertEqual(patch, exp)
Pierre-Yves Chibon 024459
Pierre-Yves Chibon 024459
        # Generate a patch for a single commit
Pierre-Yves Chibon 024459
        patch = progit.lib.git.commit_to_patch(repo, second_commit)
Pierre-Yves Chibon 024459
        exp = """Mon Sep 17 00:00:00 2001
Pierre-Yves Chibon 024459
From: Alice Author <alice@authors.tld></alice@authors.tld>
Pierre-Yves Chibon 024459
Subject: Add baz and boose to the sources
Pierre-Yves Chibon 024459
Pierre-Yves Chibon 024459
Pierre-Yves Chibon 024459
 There are more objects to consider
Pierre-Yves Chibon 024459
---
Pierre-Yves Chibon 024459
Pierre-Yves Chibon 024459
diff --git a/sources b/sources
Pierre-Yves Chibon 024459
index 9f44358..2a552bb 100644
Pierre-Yves Chibon 024459
--- a/sources
Pierre-Yves Chibon 024459
+++ b/sources
Pierre-Yves Chibon 024459
@@ -1,2 +1,4 @@
Pierre-Yves Chibon 024459
 foo
Pierre-Yves Chibon 024459
- bar
Pierre-Yves Chibon 024459
\ No newline at end of file
Pierre-Yves Chibon 024459
+ bar
Pierre-Yves Chibon 024459
+baz
Pierre-Yves Chibon 024459
+ boose
Pierre-Yves Chibon 024459
\ No newline at end of file
Pierre-Yves Chibon 024459
Pierre-Yves Chibon 024459
"""
Pierre-Yves Chibon 024459
        npatch = []
Pierre-Yves Chibon 024459
        for row in patch.split('\n'):
Pierre-Yves Chibon 024459
            if row.startswith('Date:'):
Pierre-Yves Chibon 024459
                continue
Pierre-Yves Chibon 024459
            if row.startswith('From '):
Pierre-Yves Chibon 024459
                row = row.split(' ', 2)[2]
Pierre-Yves Chibon 024459
            npatch.append(row)
Pierre-Yves Chibon 024459
Pierre-Yves Chibon 024459
        patch = '\n'.join(npatch)
Pierre-Yves Chibon 024459
        self.assertEqual(patch, exp)
Pierre-Yves Chibon 024459
Pierre-Yves Chibon c009bb
    @patch('progit.lib.notify.send_email')
Pierre-Yves Chibon c009bb
    def test_update_git_ticket(self, email_f):
Pierre-Yves Chibon c009bb
        """ Test the update_git_ticket of progit.lib.git. """
Pierre-Yves Chibon c009bb
        email_f.return_value = True
Pierre-Yves Chibon c009bb
Pierre-Yves Chibon c009bb
        # Create project
Pierre-Yves Chibon c009bb
        item = progit.lib.model.Project(
Pierre-Yves Chibon c009bb
            user_id=1,  # pingou
Pierre-Yves Chibon c009bb
            name='test_ticket_repo',
Pierre-Yves Chibon c009bb
            description='test project for ticket',
Pierre-Yves Chibon c009bb
        )
Pierre-Yves Chibon c009bb
        self.session.add(item)
Pierre-Yves Chibon c009bb
        self.session.commit()
Pierre-Yves Chibon c009bb
Pierre-Yves Chibon c009bb
        # Create repo
Pierre-Yves Chibon 6e1ebb
        self.gitrepo = os.path.join(tests.HERE, 'test_ticket_repo.git')
Pierre-Yves Chibon c009bb
        os.makedirs(self.gitrepo)
Pierre-Yves Chibon c009bb
        repo_obj = pygit2.init_repository(self.gitrepo, bare=True)
Pierre-Yves Chibon c009bb
Pierre-Yves Chibon c009bb
        repo = progit.lib.get_project(self.session, 'test_ticket_repo')
Pierre-Yves Chibon c009bb
        # Create an issue to play with
Pierre-Yves Chibon c009bb
        msg = progit.lib.new_issue(
Pierre-Yves Chibon c009bb
            session=self.session,
Pierre-Yves Chibon c009bb
            repo=repo,
Pierre-Yves Chibon c009bb
            title='Test issue',
Pierre-Yves Chibon c009bb
            content='We should work on this',
Pierre-Yves Chibon c009bb
            user='pingou',
Pierre-Yves Chibon 6e1ebb
            ticketfolder=tests.HERE
Pierre-Yves Chibon c009bb
        )
Pierre-Yves Chibon c009bb
        self.assertEqual(msg, 'Issue created')
Pierre-Yves Chibon c009bb
        issue = progit.lib.search_issues(self.session, repo, issueid=1)
Pierre-Yves Chibon 6e1ebb
        progit.lib.git.update_git_ticket(issue, repo, tests.HERE)
Pierre-Yves Chibon c009bb
Pierre-Yves Chibon c009bb
        repo = pygit2.Repository(self.gitrepo)
Pierre-Yves Chibon c009bb
        commit = repo.revparse_single('HEAD')
Pierre-Yves Chibon c009bb
Pierre-Yves Chibon c009bb
        # Use patch to validate the repo
Pierre-Yves Chibon c009bb
        patch = progit.lib.git.commit_to_patch(repo, commit)
Pierre-Yves Chibon c009bb
        exp = """Mon Sep 17 00:00:00 2001
Pierre-Yves Chibon c009bb
From: progit <progit></progit>
Pierre-Yves Chibon c009bb
Subject: Updated ticket <hash>: Test issue</hash>
Pierre-Yves Chibon c009bb
Pierre-Yves Chibon c009bb
Pierre-Yves Chibon c009bb
---
Pierre-Yves Chibon c009bb
Pierre-Yves Chibon c009bb
diff --git a/123 b/456
Pierre-Yves Chibon c009bb
new file mode 100644
Pierre-Yves Chibon c009bb
index 0000000..60f7480
Pierre-Yves Chibon c009bb
--- /dev/null
Pierre-Yves Chibon c009bb
+++ b/456
Pierre-Yves Chibon c009bb
@@ -0,0 +1 @@
Pierre-Yves Chibon a9c635
+{"status": "Open", "title": "Test issue", "private": false, "content": "We should work on this", "user": {"name": "pingou", "emails": ["bar@pingou.com", "foo@pingou.com"]}, "date_created": null, "comments": []}
Pierre-Yves Chibon c009bb
\ No newline at end of file
Pierre-Yves Chibon c009bb
Pierre-Yves Chibon c009bb
"""
Pierre-Yves Chibon c009bb
        npatch = []
Pierre-Yves Chibon c009bb
        for row in patch.split('\n'):
Pierre-Yves Chibon c009bb
            if row.startswith('Date:'):
Pierre-Yves Chibon c009bb
                continue
Pierre-Yves Chibon c009bb
            elif row.startswith('From '):
Pierre-Yves Chibon c009bb
                row = row.split(' ', 2)[2]
Pierre-Yves Chibon c009bb
            elif row.startswith('diff --git '):
Pierre-Yves Chibon c009bb
                row = row.split(' ')
Pierre-Yves Chibon c009bb
                row[2] = 'a/123'
Pierre-Yves Chibon c009bb
                row[3] = 'b/456'
Pierre-Yves Chibon c009bb
                row = ' '.join(row)
Pierre-Yves Chibon c009bb
            elif 'Updated ticket' in row:
Pierre-Yves Chibon c009bb
                row = row.split()
Pierre-Yves Chibon c009bb
                row[3] = '<hash>:'</hash>
Pierre-Yves Chibon c009bb
                row = ' '.join(row)
Pierre-Yves Chibon c009bb
            elif 'date_created' in row:
Pierre-Yves Chibon c009bb
                data = json.loads(row[1:])
Pierre-Yves Chibon c009bb
                data['date_created'] = None
Pierre-Yves Chibon c009bb
                row = '+' + json.dumps(data)
Pierre-Yves Chibon c009bb
            elif row.startswith('index 00'):
Pierre-Yves Chibon c009bb
                row = 'index 0000000..60f7480'
Pierre-Yves Chibon c009bb
            elif row.startswith('+++ b/'):
Pierre-Yves Chibon c009bb
                row = '+++ b/456'
Pierre-Yves Chibon c009bb
            npatch.append(row)
Pierre-Yves Chibon c009bb
        patch = '\n'.join(npatch)
Pierre-Yves Chibon c009bb
        self.assertEqual(patch, exp)
Pierre-Yves Chibon c009bb
Pierre-Yves Chibon c009bb
        # Test again after adding a comment
Pierre-Yves Chibon c009bb
        msg = progit.lib.add_issue_comment(
Pierre-Yves Chibon c009bb
            session=self.session,
Pierre-Yves Chibon c009bb
            issue=issue,
Pierre-Yves Chibon c009bb
            comment='Hey look a comment!',
Pierre-Yves Chibon c009bb
            user='foo',
Pierre-Yves Chibon 6e1ebb
            ticketfolder=tests.HERE
Pierre-Yves Chibon c009bb
        )
Pierre-Yves Chibon c009bb
        self.session.commit()
Pierre-Yves Chibon c009bb
        self.assertEqual(msg, 'Comment added')
Pierre-Yves Chibon c009bb
Pierre-Yves Chibon c009bb
        # Use patch to validate the repo
Pierre-Yves Chibon c009bb
        repo = pygit2.Repository(self.gitrepo)
Pierre-Yves Chibon c009bb
        commit = repo.revparse_single('HEAD')
Pierre-Yves Chibon c009bb
        patch = progit.lib.git.commit_to_patch(repo, commit)
Pierre-Yves Chibon c009bb
        exp = """Mon Sep 17 00:00:00 2001
Pierre-Yves Chibon c009bb
From: progit <progit></progit>
Pierre-Yves Chibon c009bb
Subject: Updated ticket <hash>: Test issue</hash>
Pierre-Yves Chibon c009bb
Pierre-Yves Chibon c009bb
Pierre-Yves Chibon c009bb
---
Pierre-Yves Chibon c009bb
Pierre-Yves Chibon c009bb
diff --git a/123 b/456
Pierre-Yves Chibon c009bb
index 458821a..77674a8
Pierre-Yves Chibon c009bb
--- a/123
Pierre-Yves Chibon c009bb
+++ b/456
Pierre-Yves Chibon c009bb
@@ -1 +1 @@
Pierre-Yves Chibon a9c635
-{"status": "Open", "title": "Test issue", "private": false, "content": "We should work on this", "user": {"name": "pingou", "emails": ["bar@pingou.com", "foo@pingou.com"]}, "date_created": null, "comments": []}
Pierre-Yves Chibon c009bb
\ No newline at end of file
Pierre-Yves Chibon a9c635
+{"status": "Open", "title": "Test issue", "private": false, "content": "We should work on this", "user": {"name": "pingou", "emails": ["bar@pingou.com", "foo@pingou.com"]}, "date_created": null, "comments": [{"comment": "Hey look a comment!", "date_created": null, "id": 1, "parent": null, "user": {"name": "foo", "emails": ["foo@bar.com"]}}]}
Pierre-Yves Chibon c009bb
\ No newline at end of file
Pierre-Yves Chibon c009bb
Pierre-Yves Chibon c009bb
"""
Pierre-Yves Chibon c009bb
        npatch = []
Pierre-Yves Chibon c009bb
        for row in patch.split('\n'):
Pierre-Yves Chibon c009bb
            if row.startswith('Date:'):
Pierre-Yves Chibon c009bb
                continue
Pierre-Yves Chibon c009bb
            elif row.startswith('From '):
Pierre-Yves Chibon c009bb
                row = row.split(' ', 2)[2]
Pierre-Yves Chibon c009bb
            elif row.startswith('diff --git '):
Pierre-Yves Chibon c009bb
                row = row.split(' ')
Pierre-Yves Chibon c009bb
                row[2] = 'a/123'
Pierre-Yves Chibon c009bb
                row[3] = 'b/456'
Pierre-Yves Chibon c009bb
                row = ' '.join(row)
Pierre-Yves Chibon c009bb
            elif 'Updated ticket' in row:
Pierre-Yves Chibon c009bb
                row = row.split()
Pierre-Yves Chibon c009bb
                row[3] = '<hash>:'</hash>
Pierre-Yves Chibon c009bb
                row = ' '.join(row)
Pierre-Yves Chibon c009bb
            elif 'date_created' in row:
Pierre-Yves Chibon c009bb
                data = json.loads(row[1:])
Pierre-Yves Chibon c009bb
                data['date_created'] = None
Pierre-Yves Chibon c009bb
                comments = []
Pierre-Yves Chibon c009bb
                for comment in data['comments']:
Pierre-Yves Chibon c009bb
                    comment['date_created'] = None
Pierre-Yves Chibon c009bb
                    comments.append(comment)
Pierre-Yves Chibon c009bb
                data['comments'] = comments
Pierre-Yves Chibon c009bb
                row = row[0] + json.dumps(data)
Pierre-Yves Chibon c009bb
            elif row.startswith('index'):
Pierre-Yves Chibon c009bb
                row = 'index 458821a..77674a8'
Pierre-Yves Chibon c009bb
            elif row.startswith('--- a/'):
Pierre-Yves Chibon c009bb
                row = '--- a/123'
Pierre-Yves Chibon c009bb
            elif row.startswith('+++ b/'):
Pierre-Yves Chibon c009bb
                row = '+++ b/456'
Pierre-Yves Chibon c009bb
            npatch.append(row)
Pierre-Yves Chibon c009bb
        patch = '\n'.join(npatch)
Pierre-Yves Chibon c009bb
        self.assertEqual(patch, exp)
Pierre-Yves Chibon c009bb
Pierre-Yves Chibon a945ba
Pierre-Yves Chibon a945ba
if __name__ == '__main__':
Pierre-Yves Chibon a945ba
    SUITE = unittest.TestLoader().loadTestsFromTestCase(ProgitLibGittests)
Pierre-Yves Chibon a945ba
    unittest.TextTestRunner(verbosity=2).run(SUITE)