Skip to content

Commit

Permalink
Plugin skeleton
Browse files Browse the repository at this point in the history
  • Loading branch information
fenuks committed Dec 23, 2018
0 parents commit 5a7ac68
Show file tree
Hide file tree
Showing 19 changed files with 316 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__pycache__
19 changes: 19 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]
jira = "*"
PyGithub = "*"
python-gitlab = "*"
toml = "*"

[dev-packages]
neovim = "*"
pyflakes = "*"
pylint = "*"
mypy = "*"

[requires]
python_version = "3.7"
26 changes: 26 additions & 0 deletions project.full.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"apis": {
"branch": "master",
"vsc": "git",
"token": "token",
"type": "gitlab",
"url": "url"
},
"projects": [{
"vcs": "git",
"branch": null,
"issues": {
"type": "gitlab",
"api": null
},
"reviews": {
"type": "gitlab",
"api": null
},
"ci": {
"type": "gitlab",
"api": null
}
}
]
}
7 changes: 7 additions & 0 deletions project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"apis": {
"gitlab": {
"token"
}
}
}
3 changes: 3 additions & 0 deletions rplugin/python3/base/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .issues import IssuesProvider, Issue, IssueFilters
from .reviews import MergeRequest, ReviewsProvider
from .project import Project
50 changes: 50 additions & 0 deletions rplugin/python3/base/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
from __future__ import annotations
import subprocess
from typing import Optional, List
from pathlib import Path
import json

from .constants import IssuesSoftware, ReviewSoftware, VcsSoftware


class Config:
config_name = "project.json"
apis: List[ApiConfig]
projects: List[ProjectConfig]

@staticmethod
def create(cwd: str) -> Config:
config_path = Config.get_config_path(cwd=Path(cwd))
config_data = {}
if config_path != None:
with config_path.open('r') as fp:
config_data = json.parse(fp)
return Config()

@staticmethod
def get_config_path(cwd: Path = None) -> Optional[Path]:
if cwd:
config_path = cwd / Config.config_name
if config_path.exists():
return config_path

commands = (['git', 'rev-parse', '--show-toplevel'], ['hg', 'root'])
for vcs, resp in ((command[0], subprocess.run(command, stdout=subprocess.PIPE))
for command in commands):
if resp.returncode == 0:
return Path(resp.stdout.decode().strip())

return None


class ApiConfig:
url: str
token: Optional[str]
type_: str

class ProjectConfig:
pass

class VcsConfig:
type_: str
url: str
26 changes: 26 additions & 0 deletions rplugin/python3/base/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from enum import Enum, unique


@unique
class IssuesSoftware(Enum):
bitbucket = 0
bugzilla = 1
github = 2
gitlab = 3
jira = 4
phabricator = 5


@unique
class ReviewSoftware(Enum):
bitbucket = 0
fisheye = 1
github = 2
gitlab = 3
phabricator = 4


@unique
class VcsSoftware(Enum):
hg = 0
git = 1
43 changes: 43 additions & 0 deletions rplugin/python3/base/issues.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from typing import List
from abc import ABC, abstractmethod, abstractstaticmethod
from .config import Config

class Issue:
identifier: str
title: str
author: str


class IssueFilters(ABC):
pass


class IssuesProvider(ABC):
def __init__(self, config: Config):
self.config = config

@abstractmethod
def create_issue(self) -> Issue:
pass

@staticmethod
def format_issues(issues: List[Issue]) -> List[str]:
return [
"* #{identifier} - {title}".format(
identifier=issue.identifier, title=issue.title
) for issue in issues
]

@abstractmethod
def get_issues(self, page: int, filters: IssueFilters) -> List[Issue]:
pass

@abstractmethod
def get_releases(self):
pass

@abstractstaticmethod
def get_project_name(
vcs_url: str, issues_url: str, review_url: str
) -> str:
pass
14 changes: 14 additions & 0 deletions rplugin/python3/base/project.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from abc import ABC, abstractmethod
from typing import Optional

from .issues import IssuesProvider
from .reviews import ReviewsProvider


class Project(ABC):
issues: IssuesProvider
reviews: ReviewsProvider

@abstractmethod
def __init__(self, repo_url: str, token: Optional[str]):
pass
12 changes: 12 additions & 0 deletions rplugin/python3/base/reviews.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from abc import ABC, abstractmethod
from typing import List


class MergeRequest(ABC):
pass


class ReviewsProvider(ABC):
@abstractmethod
def get(self) -> List[MergeRequest]:
pass
27 changes: 27 additions & 0 deletions rplugin/python3/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import sys
from pathlib import Path

sys.path.append(str(Path(__file__).parent))

import neovim

from base.config import Config
from providers.gitlab import GitlabProject


@neovim.plugin
class VimIssues:
def __init__(self, nvim: neovim.Nvim) -> None:
self.nvim = nvim
self.config = Config.create(nvim.funcs.cwd())

@neovim.function("ReloadConfig", sync=True)
def reload(self, args):
Config.create(self.nvim.funcs.cwd())
return 'some string'

# @neovim.command('Issues', range='', nargs='*')
# def issues(self, args, range_):
# issues = self.project.get_issues(8, 2)
# formatted = self.project.format_issues(issues)
# self.nvim.current.buffer[:] = formatted
2 changes: 2 additions & 0 deletions rplugin/python3/providers/github/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from .issues import GithubIssues
from .reviews import GithubReviews
38 changes: 38 additions & 0 deletions rplugin/python3/providers/github/issues.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from typing import List

import github
from github import Github

from base import Config, Issue, IssueFilters, IssuesProvider, MergeRequest


class GithubIssues(IssuesProvider):
def __init__(self, config: Config):
super().__init__(config)
self.api = Github()

def create_issue(self) -> Issue:
pass

def get_issues(self, page: int, filters: IssueFilters) -> List[Issue]:
r = self.api.get_repo('neovim/python-client')
return [self._get_issue_data(i) for i in r.get_issues()]

def get_merge_requests(self) -> List[MergeRequest]:
pass

def get_releases(self):
pass

@staticmethod
def get_project_name(
vcs_url: str, issues_url: str, review_url: str
) -> str:
pass

@staticmethod
def _get_issue_data(issue: github.Issue.Issue) -> Issue:
i = Issue()
i.identifier = str(issue.number)
i.title = issue.title
return i
14 changes: 14 additions & 0 deletions rplugin/python3/providers/github/project.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from typing import Optional

from github import Github

from base import IssuesProvider, Project, ReviewsProvider


class GithubProject(Project):
def __init__(self, repo_url: str, token: Optional[str]):
self.repo_url = repo_url
self.token = token

if token is not None:
self._api = Github()
8 changes: 8 additions & 0 deletions rplugin/python3/providers/github/reviews.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from typing import List

from base import MergeRequest, ReviewsProvider


class GithubReviews(ReviewsProvider):
def get(self) -> List[MergeRequest]:
pass
2 changes: 2 additions & 0 deletions rplugin/python3/providers/gitlab/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class GitlabProject():
pass
9 changes: 9 additions & 0 deletions rplugin/python3/providers/gitlab/reviews.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from typing import List

from base import MergeRequest, ReviewsProvider


class GithubReviews(ReviewsProvider):
def __init__(self, config)
def get(self) -> List[MergeRequest]:
pass
12 changes: 12 additions & 0 deletions syntax/vimissues.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
if exists('b:current_syntax')
finish
endif

syn match issuesId "\v#\d+"
hi def link issuesId Identifier

syn include @Markdown syntax/markdown.vim
syn region AWKScriptCode matchgroup=AWKCommand start=+[=\\]\@<!'+ skip=+\\'+ end=+'+ contains=@AWKScript contained
syn region AWKScriptEmbedded matchgroup=AWKCommand start=+\<awk\>+ skip=+\\$+ end=+[=\\]\@<!'+me=e-1 contains=@shIdList,@shExprList2 nextgroup=AWKScriptCode
syn cluster shCommandSubList add=AWKScriptEmbedded
hi def link AWKCommand Type
3 changes: 3 additions & 0 deletions vimrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
call plug#begin('~/.config/nvim/plugged')
Plug '~/Projects/vim/vim-issues', { 'do': ':UpdateRemotePlugins' }
call plug#end()

0 comments on commit 5a7ac68

Please sign in to comment.