Skip to content

Commit

Permalink
githubplugin: fix datatables init, sort fork list
Browse files Browse the repository at this point in the history
  • Loading branch information
Morg42 committed Nov 13, 2024
1 parent db9687a commit 3613eec
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 9 deletions.
39 changes: 32 additions & 7 deletions githubplugin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ def read_repos_from_dir(self):
continue
target = os.path.join('plugins', os.readlink(str(item)))
if not os.path.isdir(target):
self.logger.debug(f'ignoring {target}, is not directory')
self.logger.debug(f'ignoring link {item}, target {target} is not directory')
continue
try:
# plugins/priv_repos/foo_wt_bar/baz/ ->
Expand Down Expand Up @@ -520,12 +520,16 @@ def create_repo(self, name) -> bool:

repo['clean'] = True

if repo['force'] and os.path.exists(repo['link']):
self.logger.debug(f'removing link {repo["link"]} as force is set')
try:
os.remove(repo['link'])
except Exception:
pass
if os.path.exists(repo['link']):
if repo['force']:
self.logger.debug(f'removing link {repo["link"]} as force is set')
try:
os.remove(repo['link'])
except Exception:
pass
else:
self.loggerr(f'plugin symlink {repo["link"]} exists and force not set')
return False

self.logger.debug(f'creating link {repo["link"]} to {repo["rel_link_path"]}...')
try:
Expand Down Expand Up @@ -673,6 +677,27 @@ def get_github_forks(self, owner=None) -> dict:
else:
return self.gh.forks

def get_github_forklist_sorted(self) -> list:
""" return list of forks, sorted alphabetically, used forks up front """

# case insensitive sorted forks
forks = sorted(self.get_github_forks().keys(), key=lambda x: x.casefold())
sforkstop = []
sforks = []

# existing owners in self.repos
owners = [v['owner'] for k, v in self.repos.items()]

for f in forks:
if f in owners:
# put at top of list
sforkstop.append(f)
else:
# put in nowmal list below
sforks.append(f)

return sforkstop + sforks

def get_github_pulls(self, number=None) -> dict:
""" return pulls or single pull for given number """
if number:
Expand Down
4 changes: 2 additions & 2 deletions githubplugin/webif/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def index(self, action=None):
webif_pagelength=pagelength,
repos=self.plugin.repos,
init_repos=self.plugin.init_repos,
forklist=sorted(self.plugin.gh.forks.keys()),
forklist=self.plugin.get_github_forklist_sorted(),
forks=self.plugin.gh.forks,
pulls=pulls,
auth=self.plugin.gh_apikey != '',
Expand All @@ -122,7 +122,7 @@ def getRateLimit(self):
def updateForks(self):
try:
if self.plugin.fetch_github_forks(fetch=True):
return {"operation": "request", "result": "success", "data": sorted(self.plugin.gh.forks.keys())}
return {"operation": "request", "result": "success", "data": self.plugin.get_github_forklist_sorted()}
except Exception as e:
cherrypy.response.status = ERR_CODE
return {"error": str(e)}
Expand Down
2 changes: 2 additions & 0 deletions githubplugin/webif/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,8 @@
fixedHeader: true
} );

$(window).trigger('datatables_defaults');

// update rate limit data
sendData('getRateLimit', '',
function(response) {},
Expand Down

0 comments on commit 3613eec

Please sign in to comment.