IEEE.org     |     IEEE Xplore Digital Library     |     IEEE Standards     |     IEEE Spectrum     |     More Sites

Verified Commit 9b1950ad authored by Emi Simpson's avatar Emi Simpson
Browse files

Add support for multiple mattermosts/gitlabs

parent 298ae92d
......@@ -166,16 +166,19 @@ class GitHub(Source):
return 'GitHub Repo'
class GitLab(Source):
URL_REGEX = re.compile(r'https://gitlab\.com/[\w\-]+/[\w\-]+/?')
URL_REGEX = re.compile(r'https://([a-z\.\-]+\.[a-z\-]+)/[\w\-]+/[\w\-]+/?')
def expand_source(self) -> List[Source]:
domain_regex = GitLab.URL_REGEX.match(self.url)
assert domain_regex is not None, "expand_source should only be called on a valid source"
domain = domain_regex.group(1)
return [
Source(self.origin_id, self.project, self.source_type + ':issue', self.url, self.flagged),
Source(self.origin_id, self.project, self.source_type + ':merge', self.url, self.flagged),
Source(self.origin_id, self.project, f'{self.source_type}:{domain}:issue', self.url, self.flagged),
Source(self.origin_id, self.project, f'{self.source_type}:{domain}:merge', self.url, self.flagged),
] + Git(self.origin_id, self.project, 'git', self.url.rstrip('/') + '.git', self.flagged).expand_source()
def validate_source(self) -> Optional[str]:
if GitLab.URL_REGEX.match(self.url) is None:
return 'GitLab URLs should be in the form "https://gitlab.com/USER/PROJECT"'
return 'GitLab URLs should be in the form "https://your.gitlab.site/USER/PROJECT"'
else:
return None
......@@ -231,7 +234,7 @@ class WebsiteLink(Source):
return None
class Mattermost(Source):
URL_REGEX = re.compile(r'(?:https?://[\w\.\-]+.[\w]+/([a-z\-]+)/channels/([a-z\-]+)/?)|(?:https?://[\w.-]+.[\w]+/? ([a-z\d]{26}))')
URL_REGEX = re.compile(r'(?:https?://([\w\.\-]+.[\w]+)/([a-z\-]+)/channels/([a-z\-]+)/?)|(?:https?://([\w.-]+.[\w]+)/? ([a-z\d]{26}))')
@staticmethod
def display_name() -> str:
return 'Mattermost Channel'
......@@ -242,6 +245,14 @@ class Mattermost(Source):
else:
return None
def expand_source(self) -> List[Source]:
domain_regex = self.URL_REGEX.match(self.url)
assert domain_regex is not None, "expand_source should only be called on a valid source"
domain = domain_regex.group(1) or domain_regex.group(4)
return [
Source(self.origin_id, self.project, f'{self.source_type}:{domain}:issue', self.url, self.flagged),
]
def get_simplified_form(self) -> str:
"""
Returns just the ID of the channel, or team/name
......@@ -249,9 +260,9 @@ class Mattermost(Source):
match = Mattermost.URL_REGEX.match(self.url)
assert match is not None, "get_simplified_form should only be called on valid sources"
team = match.group(1)
channel = match.group(2)
chan_id = match.group(3)
team = match.group(2)
channel = match.group(3)
chan_id = match.group(5)
if team is not None:
return f'{team}/{channel}'
else:
......
......@@ -51,21 +51,20 @@ identities_format = grimoirelab
#
#[github]
#api-token = <YOUR_API_TOKEN_WHERE>
#enterprise-url = <YOUR_GITHUB_ENTERPRISE_URL>
#raw_index = github_demo_raw
#sleep-for-rate = true
#sleep-time = "300"
#enriched_index = github_demo_enriched
#
#[gitlab:issue]
#[gitlab:gitlab.com:issue]
#api-token = <YOUR_API_TOKEN_WHERE>
#raw_index = gitlab_issues_demo_raw
#enriched_index = gitlab_issues_demo_enriched
#no-archive = true
#sleep-for-rate = true
#
#[gitlab:merge]
#api-token = <YOUR_API_TOKEN_HERE>
#[gitlab:gitlab.com:merge]
#api-token = <YOUR_API_TOKEN_WHERE>
#raw_index = gitlab_merges_demo_raw
#enriched_index = gitlab_merges_demo_enriched
#no-archive = true
......@@ -130,7 +129,7 @@ sleep-time = 300
raw_index = rss_raw
enriched_index = rss_enriched
#[mattermost]
#[mattermost:your.mattermost.com]
#api-token = <YOUR_API_TOKEN_HERE>
#raw_index = mattermost_raw
#enriched_index = mattermost_enriched
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment