diff --git a/instance/migrations/0024_auto_20150911_2304.py b/instance/migrations/0024_auto_20150911_2304.py new file mode 100644 index 000000000..6b04939a3 --- /dev/null +++ b/instance/migrations/0024_auto_20150911_2304.py @@ -0,0 +1,32 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('instance', '0023_openedxinstance_ansible_source_repo_url'), + ] + + operations = [ + migrations.AlterModelOptions( + name='instancelogentry', + options={'verbose_name_plural': 'Instance Log Entries'}, + ), + migrations.AlterModelOptions( + name='serverlogentry', + options={'verbose_name_plural': 'Server Log Entries'}, + ), + migrations.AddField( + model_name='openedxinstance', + name='github_pr_number', + field=models.IntegerField(null=True, blank=True), + ), + migrations.AlterField( + model_name='openedxinstance', + name='base_domain', + field=models.CharField(max_length=50, default='example.com'), + ), + ] diff --git a/instance/models/instance.py b/instance/models/instance.py index 8bb302a28..dd1b621d5 100644 --- a/instance/models/instance.py +++ b/instance/models/instance.py @@ -204,6 +204,7 @@ class GitHubInstanceMixin(VersionControlInstanceMixin): """ github_organization_name = models.CharField(max_length=200, db_index=True) github_repository_name = models.CharField(max_length=200, db_index=True) + github_pr_number = models.IntegerField(blank=True, null=True) github_admin_organization_name = models.CharField(max_length=200, blank=True, default=settings.DEFAULT_ADMIN_ORGANIZATION) @@ -233,6 +234,15 @@ def github_base_url(self): """ return 'https://github.com/{0.fork_name}'.format(self) + @property + def github_pr_url(self): + """ + Web URL of the Github PR, or None if the PR number is not set. + """ + if self.github_pr_number is None: + return None + return '{0.github_base_url}/pull/{0.github_pr_number}'.format(self) + @property def github_branch_url(self): """ diff --git a/instance/serializers.py b/instance/serializers.py index 900cbb17a..b9f61e7fc 100644 --- a/instance/serializers.py +++ b/instance/serializers.py @@ -71,6 +71,8 @@ class Meta: 'email', 'github_base_url', 'github_branch_url', + 'github_pr_number', + 'github_pr_url', 'log_text', 'github_organization_name', 'modified', diff --git a/instance/static/html/instance/index.html b/instance/static/html/instance/index.html index 2fbd7cdb8..7fde896b8 100644 --- a/instance/static/html/instance/index.html +++ b/instance/static/html/instance/index.html @@ -50,7 +50,12 @@

| Studio: {{ selected.instance.studio_url }} -
  • {{ selected.instance.github_base_url }} | {{ selected.instance.branch_name }}
  • +
  • + {{ selected.instance.github_base_url }} {{ selected.instance.branch_name }} + + | PR#{{ selected.instance.github_pr_number }} + +
  • diff --git a/instance/tasks.py b/instance/tasks.py index d87f386e7..aa445305b 100644 --- a/instance/tasks.py +++ b/instance/tasks.py @@ -71,6 +71,7 @@ def watch_pr(): truncated_title = truncatewords(pr.title, 4) instance.name = 'PR#{pr.number}: {truncated_title} ({pr.username}) - {i.reference_name}'\ .format(pr=pr, i=instance, truncated_title=truncated_title) + instance.github_pr_number = pr.number instance.ansible_extra_settings = pr.extra_settings instance.save() diff --git a/instance/tests/models/test_instance.py b/instance/tests/models/test_instance.py index 84c3dcd0d..2a2ca6c4d 100644 --- a/instance/tests/models/test_instance.py +++ b/instance/tests/models/test_instance.py @@ -116,11 +116,13 @@ def test_github_attributes(self): """ instance = OpenEdXInstanceFactory( github_organization_name='open-craft', + github_pr_number=234, github_repository_name='edx', branch_name='test-branch', ) self.assertEqual(instance.fork_name, 'open-craft/edx') self.assertEqual(instance.github_base_url, 'https://github.com/open-craft/edx') + self.assertEqual(instance.github_pr_url, 'https://github.com/open-craft/edx/pull/234') self.assertEqual(instance.github_branch_url, 'https://github.com/open-craft/edx/tree/test-branch') self.assertEqual(instance.repository_url, 'https://github.com/open-craft/edx.git') self.assertEqual(instance.updates_feed, 'https://github.com/open-craft/edx/commits/test-branch.atom') diff --git a/instance/tests/test_tasks.py b/instance/tests/test_tasks.py index 80130e912..4d25a9f53 100644 --- a/instance/tests/test_tasks.py +++ b/instance/tests/test_tasks.py @@ -75,6 +75,7 @@ def test_watch_pr_new(self, mock_get_username_list, mock_get_pr_list_from_userna instance = OpenEdXInstance.objects.get(pk=mock_provision_instance.mock_calls[0][1][0]) self.assertEqual(instance.sub_domain, 'pr234.sandbox') self.assertEqual(instance.fork_name, 'watched/fork') + self.assertEqual(instance.github_pr_number, 234) self.assertEqual(instance.branch_name, 'watch-branch') self.assertEqual(instance.ansible_extra_settings, 'WATCH: true\r\n') self.assertEqual(