Skip to content
This repository was archived by the owner on Dec 29, 2017. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,9 @@ def parse_readme():
],
packages=[
'sirbot.pythondev',
'sirbot.pythondev.slack'
],
package_dir={
'sirbot.pythondev': 'sirbot/pythondev',
'sirbot.pythondev.slack': 'sirbot/pythondev/slack',
},
# To provide executable scripts, use entry points in preference to the
# "scripts" keyword. Entry points provide cross-platform support and
Expand Down
48 changes: 48 additions & 0 deletions sirbot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,54 @@ sqlite:

pythondev:
priority: 1
candy:
trigger: ":bdfl:"
githhub:
channel: community_projects
python_jobs:
looking: >
*Weekly who's looking thread !*

If you are looking for a job please post your resume in this thread.
looking_tips: >
We are an international community so please include your location and
if you are willing to relocate.
hiring: >
*Weekly who's hiring thread !*

If you are looking for someone please post your job in this thread.
hiring_tips: >
We are an international community so please include your company
location and policy on remote employees. A good post should include the
name of the company, the location, on-site/remote and a quick summary
of the job.
digital_ocean:
url: https://digitalocean.com
refferral: https://m.do.co/c/457f0988c477
msg: >
Here at Python Developers we host our website and Slack bot on
<{}|Digital Ocean>. If you are planning on using Digital Ocean, please
use our <{}|referral code>. You get 10 USD, while helping support the
community by contributing to hosting fees for our site and
<@sirbotalot>!
files:
msg: >
Click <{}|here> to access the {}.
intro_doc:
name: Intro doc
url: 'https://github.com/pyslackers/community/blob/master/introduction.md'
what_to_do:
name: What to do doc
url: 'https://pythondev.slack.com/files/ndevox/F4A137J0J/What_to_do_next_on_your_Python_journey'
join: >
Welcome to the community :tada:

We are glad that you have decided to join us. We have documented a few
things in the <{}|intro doc> to help you along from the beginning because
we are grand believers in the Don't Repeat Yourself principle, and it just
seems so professional!\n\n

May your :taco:s be plentiful!

logging:
version: 1
Expand Down
12 changes: 6 additions & 6 deletions sirbot/pythondev/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from sirbot.core import hookimpl, Plugin

from .github import add_to_github
from .slack import add_to_slack
from .scheduler import add_to_scheduler
from .github import GitHubEndpoint
from .scheduler import SchedulerJobs
from .slack import SlackEndpoint


@hookimpl
Expand Down Expand Up @@ -31,15 +31,15 @@ async def start(self):

if 'scheduler' in self._facades:
scheduler_facade = self._facades.get('scheduler')
add_to_scheduler(scheduler_facade)
SchedulerJobs(self._config).add(scheduler_facade)

if 'github' in self._facades:
github_facade = self._facades.get('github')
add_to_github(github_facade)
GitHubEndpoint(self._config).add(github_facade)

if 'slack' in self._facades:
slack_facade = self._facades.get('slack')
add_to_slack(slack_facade)
SlackEndpoint(self._config).add(slack_facade)

self._started = True

Expand Down
186 changes: 97 additions & 89 deletions sirbot/pythondev/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,92 +5,100 @@
logger = logging.getLogger(__name__)


def add_to_github(github):
github.add_event('issues', issues)
github.add_event('pull_request', pull_request)


async def issues(event, facades):
att = None

if event['action'] == 'opened':
att = issue_format(event, 'good')
elif event['action'] == 'closed':
att = issue_format(event, 'danger')

if att:
slack = facades.get('slack')
channel = await slack.channels.get(name='community_projects')
msg = SlackMessage(to=channel)
msg.attachments.append(att)
await slack.send(msg)


def issue_format(event, color):
att = Attachment(
fallback='issue {}'.format(event['action']),
color=color,
text=event['issue']['body'],
title='Issue {action} in <{repo_url}|{name}>: <{url}|{title}>'.format(
repo_url=event['repository']['html_url'],
url=event['issue']['html_url'],
name=event['repository']['name'],
action=event['action'],
title=event['issue']['title']
),
author_icon=event['sender']['avatar_url'],
author_name=event['sender']['login'],
author_link=event['sender']['html_url'],
footer=', '.join(label['name'] for label in event['issue']['labels'])
)

return att


async def pull_request(event, facades):
att = None

if event['action'] == 'opened':
data = {'color': 'good', 'action': 'opened'}
att = pull_request_format(event, data)
elif event['action'] == 'closed':
if event['pull_request']['merged']:
data = {'color': '#6f42c1', 'action': 'merged'}
else:
data = {'color': 'danger', 'action': 'closed'}

att = pull_request_format(event, data)

if att:
slack = facades.get('slack')
channel = await slack.channels.get(name='community_projects')
msg = SlackMessage(to=channel)
msg.attachments.append(att)
await slack.send(msg)


def pull_request_format(event, data):
footer = '+ {add} / - {del_}'.format(
add=event['pull_request']['additions'],
del_=event['pull_request']['deletions']
)

att = Attachment(
fallback='pull request {}'.format(data['action']),
title='Pull request {action} in <{repo_url}|{name}>:'
' <{url}|{title}>'.format(
repo_url=event['repository']['html_url'],
url=event['pull_request']['html_url'],
name=event['repository']['name'],
action=data['action'],
title=event['pull_request']['title'],
),
color=data['color'],
text=event['pull_request']['body'],
author_icon=event['sender']['avatar_url'],
author_name=event['sender']['login'],
author_link=event['sender']['html_url'],
footer=footer
)

return att
class GitHubEndpoint:

def __init__(self, config):
self.config = config

def add(self, github):
github.add_event('issues', self.issues)
github.add_event('pull_request', self.pull_request)

async def issues(self, event, facades):
att = None

if event['action'] == 'opened':
att = self._issue_format(event, 'good')
elif event['action'] == 'closed':
att = self._issue_format(event, 'danger')

if att:
slack = facades.get('slack')
channel = await slack.channels.get(
name=self.config['github']['channel']
)
msg = SlackMessage(to=channel)
msg.attachments.append(att)
await slack.send(msg)

def _issue_format(self, event, color):
att = Attachment(
fallback='issue {}'.format(event['action']),
color=color,
text=event['issue']['body'],
title='Issue {action} in <{repo_url}|{name}>:'
' <{url}|{title}>'.format(
repo_url=event['repository']['html_url'],
url=event['issue']['html_url'],
name=event['repository']['name'],
action=event['action'],
title=event['issue']['title']
),
author_icon=event['sender']['avatar_url'],
author_name=event['sender']['login'],
author_link=event['sender']['html_url'],
footer=', '.join(
label['name'] for label in event['issue']['labels']
)
)

return att

async def pull_request(self, event, facades):
att = None

if event['action'] == 'opened':
data = {'color': 'good', 'action': 'opened'}
att = self._pull_request_format(event, data)
elif event['action'] == 'closed':
if event['pull_request']['merged']:
data = {'color': '#6f42c1', 'action': 'merged'}
else:
data = {'color': 'danger', 'action': 'closed'}

att = self._pull_request_format(event, data)

if att:
slack = facades.get('slack')
channel = await slack.channels.get(
name=self.config['github']['channel']
)
msg = SlackMessage(to=channel)
msg.attachments.append(att)
await slack.send(msg)

def _pull_request_format(self, event, data):
footer = '+ {add} / - {del_}'.format(
add=event['pull_request']['additions'],
del_=event['pull_request']['deletions']
)

att = Attachment(
fallback='pull request {}'.format(data['action']),
title='Pull request {action} in <{repo_url}|{name}>:'
' <{url}|{title}>'.format(
repo_url=event['repository']['html_url'],
url=event['pull_request']['html_url'],
name=event['repository']['name'],
action=data['action'],
title=event['pull_request']['title'],
),
color=data['color'],
text=event['pull_request']['body'],
author_icon=event['sender']['avatar_url'],
author_name=event['sender']['login'],
author_link=event['sender']['html_url'],
footer=footer
)

return att
69 changes: 28 additions & 41 deletions sirbot/pythondev/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,53 +4,40 @@

logger = logging.getLogger(__name__)

LOOKING = '''*Weekly who's looking thread !*

If you are looking for a job please post your resume in this thread.'''
class SchedulerJobs:

LOOKING_TIPS = '''We are an international community so please include your
location and if you are willing to relocate.'''
def __init__(self, config):
self.config = config

HIRING = '''*Weekly who's hiring thread !*
def add(self, scheduler):
scheduler.add_job('looking_for_job', self.looking_for_job,
trigger='cron', day_of_week=0, hour=8)
scheduler.add_job('hiring', self.hiring,
trigger='cron', day_of_week=0, hour=8)

If you are looking for someone please post your job in this thread.'''
async def looking_for_job(self, facade):
slack = facade.get('slack')

HIRING_TIPS = '''We are an international community so please include your \
company location and policy on remote employees. A good post should include \
the name of the company, the location, on-site/remote and a quick summary of \
the job offer'''
channel = await slack.channels.get(name='python_jobs')
message = SlackMessage(to=channel)
message.text = self.config['python_jobs']['looking']
await slack.send(message)

message_tips = SlackMessage(to=channel)
message_tips.text = self.config['python_jobs']['looking_tips']
message_tips.thread = message.thread
await slack.send(message_tips)

def add_to_scheduler(scheduler):
scheduler.add_job('looking_for_job', looking_for_job,
trigger='cron', day_of_week=0, hour=8)
scheduler.add_job('hiring', hiring,
trigger='cron', day_of_week=0, hour=8)
async def hiring(self, facade):
slack = facade.get('slack')

channel = await slack.channels.get(name='python_jobs')
message = SlackMessage(to=channel)
message.text = self.config['python_jobs']['hiring']
await slack.send(message)

async def looking_for_job(facade):
slack = facade.get('slack')

channel = await slack.channels.get(name='python_jobs')
message = SlackMessage(to=channel)
message.text = LOOKING
await slack.send(message)

message_tips = SlackMessage(to=channel)
message_tips.text = LOOKING_TIPS
message_tips.thread = message.thread
await slack.send(message_tips)


async def hiring(facade):
slack = facade.get('slack')

channel = await slack.channels.get(name='python_jobs')
message = SlackMessage(to=channel)
message.text = HIRING
await slack.send(message)

message_tips = SlackMessage(to=channel)
message_tips.text = HIRING_TIPS
message_tips.thread = message.thread
await slack.send(message_tips)
message_tips = SlackMessage(to=channel)
message_tips.text = self.config['python_jobs']['hiting_tips']
message_tips.thread = message.thread
await slack.send(message_tips)
Loading