Skip to content

Commit

Permalink
Create branch names after author-stack-title instead of just author
Browse files Browse the repository at this point in the history
- This allows us to keep a new branch for every guide.  This way it's easier to
  merge changes when an editor is working on more than 1 branch at a time.
- This will also make it easier to make pull requests later since each branch
  is focused on only 1 guide.

- Fixes #58.
  • Loading branch information
durden committed May 5, 2016
1 parent 89b11a3 commit c9c412c
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 13 deletions.
4 changes: 2 additions & 2 deletions docs/github_repo_layout.rst
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ Branches
--------

Branches are currently used for suggested 'edits' to guides by the community
editors. The branches are named after the github login name of the user whose
edits triggered the creation.
editors. The branches are named to match the editor's login, stack, and title
of the guide.

Each time a user edits an existing users' guide a branch is created (or
updated). You can easily use `Github's compare functionality <https://github.com/blog/612-introducing-github-compare-view>`_ to see the edits a particular user is suggesting.
Expand Down
40 changes: 34 additions & 6 deletions pskb_website/models/article.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,10 +453,12 @@ def branch_article(article, message, new_content, author_name, email,
:returns: New article object
New branch will be named after author of changes
New branch will be named after author of changes and title
"""

branch = author_name
branch = '%s-%s-%s' % (author_name, utils.slugify_stack(article.stacks[0]),
utils.slugify(article.title))

article_sha = article.sha

# Create branch if we needed to
Expand Down Expand Up @@ -669,15 +671,23 @@ def save_branched_article_meta_data(article, author_name, email,
orig_article = read_article(article.path, rendered_text=False,
branch=u'master', repo_path=article.repo_path)

# Save list of author name and branch name. Yes, we could parse the name
# out of the branch but that is tricky b/c we'd have to disallow some
# characters in the author name to parse properly.
# Technically this would be better suited as a tuple but we serialize the
# data as json, which doesn't support tuples. Serializing tuples to json
# just comes back as a list anyway.
branch_info = [author_name, article.branch]

# Nothing to save, we're already tracking this branch
if add_branch:
if article.branch in orig_article.branches:
if branch_info in orig_article.branches:
return True

orig_article.branches.append(article.branch)
orig_article.branches.append(branch_info)
else:
try:
orig_article.branches.remove(article.branch)
orig_article.branches.remove(branch_info)
except ValueError:
# Branch isn't being tracked anyway so nothing to remove
return True
Expand Down Expand Up @@ -889,7 +899,10 @@ def __init__(self, title, author_name, filename=ARTICLE_FILENAME,
# Branch this article is on
self.branch = branch

# List of branch names where this article also exists
# List of lists [author_name, branch_name] where author_name is the
# name of the user who created the branch. Again, would be better
# suited as a list of tuples but we're using JSON for serialization and
# tuples turn into lists anyway.
self.branches = []

self._path = None
Expand Down Expand Up @@ -991,6 +1004,21 @@ def from_json(str_):
elif attr == 'stacks' and not value:
value = [u'other']

# Backwards compatability. We used to only store a list of branch
# names b/c branches were named after editor. Now branches are
# named after editor and article so storing this as list to track
# who the editor is.
elif attr == 'branches':
branches = []

for branch in value:
if isinstance(branch, (list, tuple)):
branches.append(branch)
else:
branches.append([branch, branch])

value = branches

if attr == '_publish_status' and value not in STATUSES:
raise ValueError('publish_status must be one of %s' % (STATUSES,))

Expand Down
8 changes: 4 additions & 4 deletions pskb_website/templates/article.html
Original file line number Diff line number Diff line change
Expand Up @@ -159,14 +159,14 @@ <h5>Community suggestions</h5>
{% if article.branch != 'master' %}
<li>
See {{article.author_name}}'s <a href="{{article|url_for_article(branch='master')}}">original version of this guide</a> or
{{article.branch}}'s <a href="https://github.com/{{article.repo_path}}/compare/master...{{article.branch}}" target="_blank">suggestions on github</a>.
these <a href="https://github.com/{{article.repo_path}}/compare/master...{{article.branch}}" target="_blank">suggestions on github</a>.
</li>
{% endif %}

{% for branch in branches %}
{% if branch != 'master' and branch != article.branch %}
{% for branch_author, branch_name in branches %}
{% if branch_name != 'master' and branch_name != article.branch %}
<li>
See {{branch}}'s <a href="{{article|url_for_article(branch=branch)}}"> version of this guide</a> or their <a href="https://github.com/{{article.repo_path}}/compare/master...{{branch}}"
See {{branch_author}}'s <a href="{{article|url_for_article(branch=branch_name)}}"> version of this guide</a> or their <a href="https://github.com/{{article.repo_path}}/compare/master...{{branch_name}}"
target="_blank">suggestions on github</a>.
</li>
{% endif %}
Expand Down
2 changes: 1 addition & 1 deletion pskb_website/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ def render_article_view(request_obj, article, only_visible_by_user=None):

# Always include a link to original article if this is a branched version
if article.branch != u'master':
branches.append(u'master')
branches.append([article.author_name, u'master'])

g.header_white = True

Expand Down

0 comments on commit c9c412c

Please sign in to comment.