#6 Ship a custom repo_info template with information specific for dist-git
Merged 8 years ago by pingou. Opened 8 years ago by pingou.

file modified
+1
@@ -2,3 +2,4 @@ 

  include README.rst

  include dist_git_auth.py

  include dist_git_auth_tests.py

+ recursive-include template *

@@ -0,0 +1,434 @@ 

+ {% extends "repo_master.html" %}

+ 

+ 

+ {% block title %}{{ select.capitalize() }} - {{

+     repo.namespace + '/' if repo.namespace }}{{ repo.name }}{% endblock %}

+ {% set tag = "home" %}

+ 

+ {% block header %}

+   <meta name="go-import" content="{{ config.get('APP_URL').split('://', 1)[1] }}{{ repo.fullname }} git {{ config.get('GIT_URL_GIT') }}{{ repo.fullname }}.git">

+   <style>

+   a.koji {

+     padding-left: 20px;

+     background: url(https://fedoraproject.org/static/images/icons/fedora-infra-icon_koji.png) 0 50% no-repeat;

+   }

+   a.bodhi {

+     padding-left: 20px;

+     background: url(https://fedoraproject.org/static/images/icons/fedora-infra-icon_bodhi.png) 0 50% no-repeat;

+   }

+   a.bugz {

+     padding-left: 20px;

+     background: url(https://fedoraproject.org/static/images/icons/fedora-infra-icon_bugzilla.png) 0 50% no-repeat;

+   }

+   a.community {

+     padding-left: 20px;

+     background: url(https://apps.fedoraproject.org/tagger/images/favicons/16_beefy.png) 0 50% no-repeat;

+   }

+   a.koschei {

+     padding-left: 33px;

+     background: url(https://admin.fedoraproject.org/pkgdb/static/icon_koschei.png) 0 50% no-repeat;

+   }

+   </style>

+ 

+ {% endblock %}

+ 

+ {% block repo %}

+   <div class="row">

+     {% if g.repo_obj and g.repo_obj.is_empty %}

+       <div class="col-md-8">

+         <div class="alert {% if category == 'error' %}alert-warning{% else %}alert-info{%endif%}" role="alert">

+           <p>This repo is brand new!</p>

+             {% if authenticated and g.repo_committer %}

+               <p>If you already have a git repo:</p>

+               <pre>git remote add origin {{ config.get('GIT_URL_SSH') }}{% if repo.parent %}forks/{% endif %}{{ repo.fullname }}.git

+ git push -u origin master</pre>

+ 

+               <p>If you have not created your git repo yet:</p>

+               <pre>git clone {{ config.get('GIT_URL_SSH') }}{% if repo.parent %}forks/{% endif %}{{ repo.fullname }}.git

+ cd {{ repo.name }}

+ touch README.rst

+ git add README.rst

+ git commit -m "Add README file"

+ git push -u origin master</pre>

+             {% else %}

+               <p>The Project Creator has not pushed any code yet</p>

+             {% endif %}

+         </div>

+       </div>

+     {% else %}

+         <div class="col-md-8">

+           <section id="pkginfo">

+             <div class="row">

+               <div class="col-md-12" id="pkgdescription"></div>

+             </div>

+             <br/>

+             <div class="row">

+               <div class="col-md-2">

+                 <a class="koji"

+                   href="http://koji.fedoraproject.org/koji/search?type=package&match=glob&terms={{ repo.name }}">

+                   Builds status

+                 </a>

+               </div>

+               <div class="col-md-2">

+                 <a class="bodhi"

+                   href="https://bodhi.fedoraproject.org/updates/?packages={{ repo.name }}">

+                   Updates status

+                 </a>

+               </div>

+               <div class="col-md-2">

+                 <a class="bugz"

+                   href="https://apps.fedoraproject.org/packages/{{ repo.name }}/bugs">

+                   Bug reports

+                 </a>

+               </div>

+               <div class="col-md-2">

+                 <a class="community"

+                   href="https://apps.fedoraproject.org/packages/{{ repo.name }}">

+                   Packages

+                 </a>

+               </div>

+               <div class="col-md-2">

+                 <a class="koschei"

+                   href="https://apps.fedoraproject.org/koschei/package/{{ repo.name }}">

+                   Koschei status

+                 </a>

+               </div>

+             </div>

+             <br/>

+           </section>

+           {% if readme %}

+             <section class="readme">

+               {{ readme | noJS | safe }}

+             </section>

+             {% else %}

+             <section class="no-readme">

+               <div class="card">

+                 <div class="card-header text-xs-center text-muted p-t-2 p-b-2">

+                   The {{repo.name}} project's README file is empty or unavailable.

+                 </div>

+               </div>

+             </section>

+           {% endif %}

+         </div>

+     {% endif %}

+       <div class="col-md-4">

+         <div class="card">

+           <div class="card-block">

+             <h5><strong>Contributors</strong></h5>

+             <div class="m-b-2">

+               <div>

+                 <a href="{{ url_for('view_user', username=repo.user.user)}}">

+                   {{ repo.user.default_email | avatar(20) | safe }}

+                   {{ repo.user.fullname }} ({{ repo.user.user }})

+                 </a>

+                 -  main admin

+               </div>

+               {% for access in repo.contributors %}

+                 {% for user in repo.contributors[access] %}

+                   <div>

+                     <a href="{{ url_for('view_user', username=user.user)}}">

+                       {{ user.default_email | avatar(20) | safe }}

+                       {{ user.fullname }} ({{ user.user }})

+                     </a>

+                     - {{ access }}

+                   </div>

+                 {% endfor %}

+               {% endfor %}

+               {% for access in repo.contributor_groups %}

+                 {% for group in repo.contributor_groups[access] %}

+                   <div>

+                     <a href="{{ url_for('view_group', group=group.group_name)}}">

+                       @{{ group.group_name }}

+                     </a>

+                     - {{ access }}

+                   </div>

+                 {% endfor %}

+               {% endfor %}

+             </div>

+             <h5><strong>Branches</strong></h5>

+             <div class="m-b-2">

+               {% if head %}

+               <div id="branch-{{ head }}" class="repoinfo-branchlistitem row">

+                 <div class="branch_name col-md-8">

+                   {% if branchname == head %}

+                   <span class="oi text-muted" data-glyph="random"

+                     title="Default branch"></span>

+                   <strong title="Currently viewing branch {{ head }}" data-toggle="tooltip">{{ head }}</strong>

+                   {% else  %}

+                   <span class="oi text-muted" data-glyph="random"

+                     title="Default branch"></span>

+                   <a href="{{ url_for('view_repo_branch',

+                     repo=repo.name,

+                     username=username,

+                     namespace=repo.namespace,

+                     branchname=head) }}"

+                     title="{{ head }}" data-toggle="tooltip">

+                     {{ head }}

+                   </a>

+                   {% endif %}

+                 </div>

+                 <div class="branch_del col-md-4">

+                   <span class="oi text-muted" data-glyph="star"

+                     title="Default branch"></span>

+                 </div>

+               </div>

+               {% endif %}

+ 

+             {% for branch in g.branches if branch != head%}

+               <div id="branch-{{ branch | replace('/', '__') }}" class="repoinfo-branchlistitem row">

+                 <div class="branch_name col-md-8">

+                   <span class="oi text-muted" data-glyph="random"></span>

+                   {% if branchname != branch %}

+                   <a class="" href="{{ url_for('view_repo_branch',

+                     repo=repo.name,

+                     username=username,

+                     namespace=repo.namespace,

+                     branchname=branch) }}"

+                     title="{{ branch }}" data-toggle="tooltip">{{ branch }}

+                   </a>

+                   {% else %}

+                   <strong title="Currently viewing branch {{branch}}" data-toggle="tooltip">{{ branch }}</strong>

+                   {% endif %}

+ 

+                 </div>

+                 <div class="branch_del col-md-4">

+                   {% if g.repo_committer and branch != head %}

+                   <form id="delete_branch_form-{{ branch | replace('/', '__') }}" action="{{

+                     url_for('.delete_branch',

+                             repo=repo.name,

+                             username=username,

+                             namespace=repo.namespace,

+                             branchname=branch)

+                     }}" method="post" class="inline icon del_icon"

+                     onsubmit="return confirm('Are you sure you want to remove the branch: {{ branch }}?\nThis cannot be un-done!');">

+                     {{ form.csrf_token }}

+                     <a title="Remove branch {{ branch }}" href="#"

+                       onclick="$('#delete_branch_form-{{ branch | replace('/', '__') | replace('.', '\\\\.') }}').submit();">

+                       <span class="oi" data-glyph="trash"></span>

+                     </a>

+                   </form>

+                   {% endif %}

+                 </div>

+               </div>

+               {% endfor %}

+             </div>

+             <h5><strong>Source GIT URLs</strong>{% if

+               (authenticated and g.repo_committer) or

+               (config['DOC_APP_URL'] and repo and

+                       repo.settings.get('project_documentation', True))

+               %}

+                   <span class="pull-xs-right"><a data-toggle="collapse" href="#moregiturls"

+                   aria-expanded="false" aria-controls="moregiturls"

+                   id="more_gits">more</a></span>{%endif%}</h5>

+             <div>

+               <div class="form-group">

+                 <div class="input-group input-group-sm">

+                   <div class="input-group-addon">SSH</div>

+                   <input class="form-control" type="text" value="{{

+                     config.get('GIT_URL_SSH') }}{{ repo.fullname }}.git" readonly>

+                 </div>

+               </div>

+               <div class="form-group">

+                 <div class="input-group input-group-sm">

+                   <div class="input-group-addon">GIT</div>

+                   <input class="form-control" type="text" value="{{

+                     config.get('GIT_URL_GIT') }}{{ repo.fullname }}.git" readonly>

+                 </div>

+               </div>

+               <div class="collapse" id="moregiturls">

+                 {% if config['DOC_APP_URL']

+                     and repo

+                     and repo.settings.get('project_documentation', True) %}

+                   <h5><strong>Docs GIT URLs</strong></h5>

+                   {% if authenticated and g.repo_committer %}

+                     <div class="form-group">

+                       <div class="input-group input-group-sm">

+                         <div class="input-group-addon">SSH</div>

+                         <input class="form-control" type="text" value="{{

+                           config.get('GIT_URL_SSH') }}docs/{{ repo.fullname }}.git" readonly>

+                       </div>

+                     </div>

+                   {% endif %}

+                   <div class="form-group">

+                     <div class="input-group input-group-sm">

+                       <div class="input-group-addon">GIT</div>

+                       <input class="form-control" type="text" value="{{

+                         config.get('GIT_URL_GIT') }}docs/{{ repo.fullname }}.git" readonly>

+                     </div>

+                   </div>

+                 {% endif %}

+                 {% if authenticated and g.repo_committer %}

+                   {% if config.get('ENABLE_TICKETS', True)

+                      and repo.settings.get('issue_tracker', True) %}

+                     <h5><strong>Issues GIT URLs</strong></h5>

+                     <div class="form-group">

+                       <div class="input-group input-group-sm">

+                         <div class="input-group-addon">SSH</div>

+                         <input class="form-control" type="text" value="{{

+                           config.get('GIT_URL_SSH') }}tickets/{{ repo.fullname }}.git" readonly>

+                       </div>

+                     </div>

+                   {% endif %}

+                   <h5><strong>Pull Requests GIT URLs</strong></h5>

+                   <div class="form-group">

+                     <div class="input-group input-group-sm">

+                       <div class="input-group-addon">SSH</div>

+                       <input class="form-control" type="text" value="{{

+                         config.get('GIT_URL_SSH') }}requests/{{ repo.fullname }}.git" readonly>

+                     </div>

+                   </div>

+                 {% endif %}

+               </div>

+             </div>

+           </div>

+           <div class="repo_date" title="{{repo.date_created}}">

+               created {{repo.date_created|humanize}}

+           </div>

+         </div>

+ 

+         {% if last_commits %}

+           <div class="card">

+             <div class="card-header">

+               <strong>Recent Commits in

+                 <span class="pr-toplabel">

+                   <span class="oi" data-glyph="random"></span>

+                   {{branchname}}

+                 </span>

+               </strong>

+             </div>

+             <div class="card-block p-a-0">

+               <div class="list-group list-group-flush">

+                 {% for commit in last_commits %}

+                   <a href="{{

+                       url_for('view_commit',

+                       repo=repo.name,

+                       username=username,

+                       namespace=repo.namespace,

+                       commitid=commit.hex) }}" class="list-group-item">

+                     <div class="commitdate" title="{{ commit.commit_time|format_ts }}">

+                       <small>

+                         <strong>

+                           {{ commit.author | author2avatar(20) | safe }}

+                           {{ commit.author.name }}

+                         </strong>

+                         commited {{ commit.commit_time|humanize }}

+                       </small>

+                     </div>

+                     <div><small>

+                       {{ commit.message.split('\n')[0] }}

+                     </small></div>

+                   </a>

+                 {% endfor %}

+               </div>

+               </div>

+             </div>

+           </div>

+         {% endif %}

+       </div>

+     </div>

+ 

+ 

+ {% endblock %}

+ 

+ {% block jscripts %}

+ {{ super() }}

+ <script type="text/javascript">

+ $(document).ready(function() {

+   $(".extra_gits").hide();

+   $.ajax({

+     url: 'https://apps.fedoraproject.org/mdapi/rawhide/pkg/{{ repo.name }}',

+     type: 'GET',

+     dataType: 'jsonp',

+     success: function(res) {

+       $( "#pkgdescription" ).text(res['description']);

+     }

+   });

+ });

+ 

+ $(function() {

+   $( "#more_gits" ).click(function() {

+       if ($( "#more_gits" ).html() == 'more') {

+         $( "#more_gits" ).html('less');

+       } else {

+         $( "#more_gits" ).html('more');

+       }

+   });

+ 

+   {% if authenticated and g.repo_committer %}

+   $.ajax({

+     url: '{{ url_for("internal_ns.get_pull_request_ready_branch") }}' ,

+     type: 'POST',

+     data: {

+       namespace: "{{ repo.namespace if repo.namespace }}",

+       repo: "{{ repo.name }}",

+       repouser: "{{ repo.user.user if repo.is_fork else '' }}",

+       csrf_token: "{{ form.csrf_token.current_token }}",

+     },

+     dataType: 'json',

+     success: function(res) {

+       if (res.code == 'OK'){

+         for (branch in res.message.new_branch){

+           var url = "{{ url_for(

+             'new_request_pull',

+             repo=repo.name,

+             username=repo.user.user if repo.is_fork else None,

+             namespace=repo.namespace,

+             branch_to=head or 'master',

+             branch_from='') }}";

+           html = '<div class="alert alert-info" role="alert"> \

+                 The branch ' + branch +' contains '

+                 + res.message.new_branch[branch].length

+                 +  ' commits not in the main branch \

+                 <span class="pr-toplabel"> \

+                 <span class="oi" data-glyph="random"> </span> \

+                 {{ head }}</span> \

+                 <div id="request_pull" class="col-md-2"> \

+                 <a class="btn btn-primary btn-sm" href="' + url + branch + '"> Create pull request </a> \

+                 </div></div>';

+           /*$($('.bodycontent').find('.row').children()[0]).before(html);*/

+           {% if repo.is_fork %}

+           html2 = ' \

+                 <a class="small label label-sm label-primary" data-toggle="tooltip" \

+                 href="' + url + branch + '"\

+                  title="' + branch +' contains '

+                  + res.message.new_branch[branch].length+' \

+                  commit not in the upstream project. Click to create new PR now.'+'"> New PR</a> \

+                 </div>';

+           {% else %}

+           html2 = ' \

+                 <a class="small label label-sm label-primary" data-toggle="tooltip" \

+                 href="' + url + branch + '"\

+                  title="' + branch +' contains '

+                  + res.message.new_branch[branch].length+' \

+                  commit not in the main branch. Click to create new PR now.'+'"> New PR</a> \

+                 </div>';

+           {%endif%}

+           $('#branch-' + branch.replace('.', '\\.').replace('/', '__')

+             + ' .branch_del').prepend(html2);

+           $('[data-toggle="tooltip"]').tooltip({placement : 'bottom'});

+         }

+         for (branch in res.message.branch_w_pr){

+           var url = "{{ url_for(

+               'request_pull',

+               repo=repo.name,

+               username=None,

+               namespace=repo.namespace,

+               requestid=-100) }}";

+           url = url.replace(-100, res.message.branch_w_pr[branch]);

+           var html = ' \

+               <a class="small label label-sm label-success" data-toggle="tooltip" \

+               href="' + url + '"\

+                title="' + branch +' is already in an opened pull-request">'

+                + 'PR#' + res.message.branch_w_pr[branch] + ' </a> \

+               </div>';

+           $('#branch-' + branch.replace('.', '\\.').replace('/', '__')

+             + ' .branch_del').prepend(html);

+           $('[data-toggle="tooltip"]').tooltip({placement : 'bottom'});

+         }

+       }

+     }

+   });

+   {% endif %}

+ });

+ </script>

+ {% endblock %}

This allows providing some Fedora specific information for this Fedora
specific instance of pagure.

Signed-off-by: Pierre-Yves Chibon pingou@pingoured.fr

The hardcoded loopback IP address seems like it wouldn't work for users. Should this be a DNS name?

The code looks fine (though I suggest fixing that loopback address), but it seems like a lot of the template would be the same as the Pagure template code. Is there an opportunity to share template code (and JavaScript too) so that it's not repeating code between the projects?

LGTM.

The template basically comes from pagure, I just tweaked it a little to adjust it for dist-git. There has been thought about supporting a more proper theming approach than this override we're using here, but both @ryanlerch and I are missing the experience in this domain to know how to do this properly.
So currently, override the default template is our way to go :(

Actually hitting mdapi instead of my local dev instance sounds indeed appealing, let's try to do that :)

rebased

8 years ago

URL adjusted and tested locally, works fine.

Thanks for the review!

Pull-Request has been merged by pingou

8 years ago
Metadata