Skip to content
This repository has been archived by the owner on Aug 22, 2022. It is now read-only.

Commit

Permalink
Merge pull request #4 from open-craft/smarnach/add-pr-link
Browse files Browse the repository at this point in the history
Add PR number to Github instances and show PR link in the Web UI.
  • Loading branch information
smarnach committed Sep 14, 2015
2 parents 9d19cba + 3b2ecae commit 8a4ce6f
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 1 deletion.
32 changes: 32 additions & 0 deletions instance/migrations/0024_auto_20150911_2304.py
Original file line number Diff line number Diff line change
@@ -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'),
),
]
10 changes: 10 additions & 0 deletions instance/models/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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):
"""
Expand Down
2 changes: 2 additions & 0 deletions instance/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
7 changes: 6 additions & 1 deletion instance/static/html/instance/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,12 @@ <h3>
|
<span>Studio: <a href="{{ selected.instance.studio_url }}" target="_new">{{ selected.instance.studio_url }}</a></span>
</li>
<li><a href="{{ selected.instance.github_branch_url }}" target="_new">{{ selected.instance.github_base_url }}</a> | {{ selected.instance.branch_name }}</li>
<li>
<a href="{{ selected.instance.github_branch_url }}" target="_new">{{ selected.instance.github_base_url }}</a> {{ selected.instance.branch_name }}
<span ng-if="selected.instance.github_pr_number">
| <a href="{{ selected.instance.github_pr_url }}" target="_new">PR#{{ selected.instance.github_pr_number }}</a>
</span>
</li>
</ul>
</div>
<div ng-switch="selected.instance.status">
Expand Down
1 change: 1 addition & 0 deletions instance/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
2 changes: 2 additions & 0 deletions instance/tests/models/test_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
1 change: 1 addition & 0 deletions instance/tests/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 8a4ce6f

Please sign in to comment.