Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions backend/code_review_backend/app/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,9 @@
# Cors open by default in dev
CORS_ORIGIN_ALLOW_ALL = True

# Use production Phabricator instance by default
PHABRICATOR_HOST = "https://phabricator.services.mozilla.com"

# Heroku settings override to run the web app in production mode
if "DYNO" in os.environ:
logger.info("Setting up Heroku environment")
Expand Down Expand Up @@ -215,5 +218,9 @@
# Setup Cors allowed domains
CORS_ORIGIN_WHITELIST = taskcluster.secrets.get("cors-domains", [])

# Override Phabricator instance
if "PHABRICATOR" in taskcluster.secrets:
PHABRICATOR_HOST = taskcluster.secrets["PHABRICATOR"]["url"]

else:
logger.info("Skipping taskcluster configuration")
6 changes: 6 additions & 0 deletions backend/code_review_backend/issues/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

import urllib.parse
import uuid

from django.conf import settings
from django.db import models

LEVEL_WARNING = "warning"
Expand Down Expand Up @@ -47,6 +49,10 @@ class Revision(PhabricatorModel):
def __str__(self):
return f"D{self.id} - {self.title}"

@property
def phabricator_url(self):
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: maybe specify phabricator_revision_url

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My idea was to later add phabricator_url on the different model if needed (for Repo, Diff, mayber later Build, ..)

return urllib.parse.urljoin(settings.PHABRICATOR_HOST, f"D{self.id}")


class Diff(PhabricatorModel):
revision = models.ForeignKey(
Expand Down
11 changes: 10 additions & 1 deletion backend/code_review_backend/issues/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,19 @@ class RevisionSerializer(serializers.ModelSerializer):
diffs_url = serializers.HyperlinkedIdentityField(
view_name="revision-diffs-list", lookup_url_kwarg="revision_id"
)
phabricator_url = serializers.URLField(read_only=True)

class Meta:
model = Revision
fields = ("id", "repository", "phid", "title", "bugzilla_id", "diffs_url")
fields = (
"id",
"repository",
"phid",
"title",
"bugzilla_id",
"diffs_url",
"phabricator_url",
)


class DiffSerializer(serializers.ModelSerializer):
Expand Down
3 changes: 3 additions & 0 deletions backend/code_review_backend/issues/tests/test_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def test_list_diffs(self):
"title": "Revision 1",
"bugzilla_id": 10000,
"diffs_url": "http://testserver/v1/revision/1/diffs/",
"phabricator_url": "https://phabricator.services.mozilla.com/D1",
},
"phid": "PHID-DIFF-1",
"review_task_id": "task-0",
Expand All @@ -78,6 +79,7 @@ def test_list_diffs(self):
"title": "Revision 2",
"bugzilla_id": 10001,
"diffs_url": "http://testserver/v1/revision/2/diffs/",
"phabricator_url": "https://phabricator.services.mozilla.com/D2",
},
"phid": "PHID-DIFF-2",
"review_task_id": "task-1",
Expand All @@ -94,6 +96,7 @@ def test_list_diffs(self):
"title": "Revision 1",
"bugzilla_id": 10000,
"diffs_url": "http://testserver/v1/revision/1/diffs/",
"phabricator_url": "https://phabricator.services.mozilla.com/D1",
},
"phid": "PHID-DIFF-3",
"review_task_id": "task-2",
Expand Down