/** * @dataProvider commits */ public function testCreateCommitMessage($revisions, $expected) { $laws = []; $commit = []; foreach ($revisions as $revision) { $law_id = $revision['law_id']; if (!isset($laws[$law_id])) { $laws[$law_id] = Law::create(['id' => $law_id]); } $commit[$law_id] = new Revision(['law_id' => $law_id, 'date' => $revision['date'], 'comment' => $revision['comment']]); } $this->assertEquals($expected, $this->formatter->createCommitMessage('test', $commit)); }
public function handleOneDayOfLaws($date) { $commits = $this->groupRevisionsForCommits($date); // Since there are lots of old commits, we process them in batches of one day. if (!$this->isFutureDate($date)) { $branch = 'master'; $this->git->gitCheckout($branch); $messages = []; $affected = []; foreach ($commits as $commit) { $this->doChanges($commit); $messages[] = $this->formatter->createCommitMessage($branch, $commit); $affected = array_merge($affected, array_keys($commit)); } if (count($messages) > 1) { foreach ($messages as &$m) { $m = '- ' . $m; } } $message = implode("\n", $messages); $this->git->gitCommit($date, $message); DB::table('law_revisions')->where('date', $date)->whereIn('law_id', $affected)->update(['r_' . $this->git->repository_name => 1]); } else { foreach ($commits as $commit) { $branch = $this->getBranchName($commit, $date); $this->git->gitCheckout($branch); $this->doChanges($commit); $message = $this->formatter->createCommitMessage($branch, $commit); $this->git->gitCommit($date, $message); if ($branch != 'master') { $this->git->gitPush($branch); $pr_title = $this->formatter->createPRTitle($branch, $commit); $pr_body = $this->formatter->createPRBody($branch, $commit); $this->git->gitSendPullRequest($branch, $pr_title, $pr_body); } DB::table('law_revisions')->where('date', $date)->whereIn('law_id', array_keys($commit))->update(['r_' . $this->git->repository_name => 1]); } } return count($commits); }