how we learned to stop worrying and love (or at least live with) github

29
How We Learned To Stop Worrying And Love (Or At Least Live With) GitHub Open Source Bridge 2015 Jen Griffin (@kareila) Athena Yao (@afuna) Dreamwidth Studios (dreamwidth.org)

Upload: dreamwidth

Post on 06-Aug-2015

27 views

Category:

Technology


1 download

TRANSCRIPT

Page 1: How We Learned To Stop Worrying And Love (or at least live with) GitHub

How We Learned To Stop Worrying And Love (Or At Least Live With) GitHub

Open Source Bridge 2015

Jen Griffin (@kareila)Athena Yao (@afuna)

Dreamwidth Studios (dreamwidth.org)

Page 2: How We Learned To Stop Worrying And Love (or at least live with) GitHub

How We Learned To Stop Worrying And Love (Or At Least Live With)

GitHub

These slides may be downloaded from

http://slideshare.net/dreamwidth

Our code may be downloaded fromhttps://github.com/afuna/ghi-assist

Page 3: How We Learned To Stop Worrying And Love (or at least live with) GitHub

What Is GitHub?

GitHub is the most widely used platform for managing open source projects. It provides:

• source code management• issue management (aka bug tracking)• collaboration tools

Anyone can easily sign up for a free account, modify a copy of an open source project, and request for their changes to be accepted.

Page 4: How We Learned To Stop Worrying And Love (or at least live with) GitHub
Page 5: How We Learned To Stop Worrying And Love (or at least live with) GitHub
Page 6: How We Learned To Stop Worrying And Love (or at least live with) GitHub

Why Use GitHub?

Strengths Weaknesses

• popularity / ubiquity

• ease of use

• powerful features

• limited/difficult customization

• Git (SCM) is hard

• all-or-nothing permissions

It is possible to use GitHub as a basic code repository and use other products for the rest of your project’s workflow.

Page 7: How We Learned To Stop Worrying And Love (or at least live with) GitHub

Case History: Dreamwidth

• 2008: self-hosted Mercurial + Bugzilla

• 2012: GitHub + Bugzilla

• 2014: GitHub only

Our code’s migration was planned and orderly.

Switching issue trackers was not.

Page 8: How We Learned To Stop Worrying And Love (or at least live with) GitHub
Page 9: How We Learned To Stop Worrying And Love (or at least live with) GitHub

Why Did We Wait?

• More Flexible, Powerful Metadata

• Easier Drop-In Contributions

• Better Permissions & Privacy

Bottom line: Bugzilla is a more fully featured bug tracker than GitHub Issues.

Page 10: How We Learned To Stop Worrying And Love (or at least live with) GitHub

Considering Our Options

• Start again with Bugzilla - rejected because we didn’t want to continue self-hosting

• Use a different hosted bug tracker - rejected because we couldn’t find anything that fit our needs (YMMV)

• Set up an issues-only GitHub repo with admin access for all - rejected as messy and confusing

• What we finally decided - use GitHub Issues normally and do our best to work around rough spots

Page 11: How We Learned To Stop Worrying And Love (or at least live with) GitHub
Page 12: How We Learned To Stop Worrying And Love (or at least live with) GitHub

GitHub Permissions (For Teams)

• Anyone: can browse, create and comment on issues, fork the code, and submit pull requests.

• Members: can also have issues assigned to them by admins and be referenced by name in comments.

• Admins: can commit code changes and make changes to issues, including labels and assignments.

Page 13: How We Learned To Stop Worrying And Love (or at least live with) GitHub

Permissions: What We Wanted

• Anyone: can browse, create and comment on issues, fork the code, and submit pull requests.

• Members: can also assign issues to themselves, be referenced by name in comments, and categorize existing issues with labels.

• Admins: can commit code changes and make changes to issues, including labels and assignments.

Page 14: How We Learned To Stop Worrying And Love (or at least live with) GitHub

Enter The API

GitHub provides a programming interface for interacting with issues

and pull requests:https://developer.github.com/

Notifications are sent when items are opened, closed, or commented on. Since anyone can comment, anyone can trigger API actions via specially formatted comments!

Page 15: How We Learned To Stop Worrying And Love (or at least live with) GitHub

How It Works

• The service is similar to a chatbot. It listens for GitHub API events and responds as desired.

• In order to execute the requested actions, it will need to be linked to a GitHub account that has access to commit the changes.

• You will probably want to give it a name that makes clear it is an automated process.

Page 16: How We Learned To Stop Worrying And Love (or at least live with) GitHub

Currently Defined Actions

Assign Related Issue: If a pull request claims to fix an issue, assign the issue to the author

Claim Issue: Assign[*] issue to anyone who leaves a comment saying “claim”, “claiming” or “claimed”

Add Labels: Labels can be added via comments by prefixing the name of the label (##labelname)

Page 17: How We Learned To Stop Worrying And Love (or at least live with) GitHub

Stop! Demo Time!

Page 18: How We Learned To Stop Worrying And Love (or at least live with) GitHub

Flow of Control

Page 19: How We Learned To Stop Worrying And Love (or at least live with) GitHub
Page 20: How We Learned To Stop Worrying And Love (or at least live with) GitHub

Anatomy of a Webhook

1. Verify request came from GitHub2. Determine event type3. Do some action based on the

payload contents

Page 21: How We Learned To Stop Worrying And Love (or at least live with) GitHub

def signature_valid(self, data=None, signed_data=None, digest=sha1):

mac = hmac.new(self.secret, msg=data,

digestmod=digest) try: return hmac.compare_digest(

mac.hexdigest(), signed_data)

except AttributeError: # < Python 2.7.7 return mac.hexdigest() == signed_data

Page 22: How We Learned To Stop Worrying And Love (or at least live with) GitHub

signature_header = request.headers.get('X-Hub-Signature')

digest, signature = signature_header.split('=’)

if digest != "sha1": abort(501, "'%s' not supported." % digest)

if not webhook.signature_valid( data=request.body.read(),

signed_data=signature): abort(403, "Signature does not match expected value.")

Page 23: How We Learned To Stop Worrying And Love (or at least live with) GitHub

Anatomy of a Webhook

1. Verify request came from GitHub2. Determine event type3. Do some action based on the

payload contents

Page 24: How We Learned To Stop Worrying And Love (or at least live with) GitHub

event = request.headers.get('X-GitHub-

Event')

Page 25: How We Learned To Stop Worrying And Love (or at least live with) GitHub

Anatomy of a Webhook

1. Verify request came from GitHub2. Determine event type3. Do some action based on the

payload contents

Page 26: How We Learned To Stop Worrying And Love (or at least live with) GitHub

CLAIM_PATTERN = re.compile(r'\bclaim(?:ed|ing)?\b', re.I)

class ClaimHook(Hook): def should_perform_action(self, payload, api):

if payload["issue"]["assignee"] is None \

and CLAIM_PATTERN.search( payload["comment"]["body"]): return True else: return False

Page 27: How We Learned To Stop Worrying And Love (or at least live with) GitHub

headers = { 'User-Agent': "GHI Assist Bot",

'Authorization': "token %s" % self.token, }response = requests.request("PATCH","https://api.github.com…",

headers=headers, data=json.dumps({"assignee": assignee}))

Page 28: How We Learned To Stop Worrying And Love (or at least live with) GitHub

Resources

Code for our GitHub assistant:https://github.com/afuna/ghi-assist

GitHub’s API reference:https://developer.github.com/

Download link for our slides:http://slideshare.net/dreamwidth

Page 29: How We Learned To Stop Worrying And Love (or at least live with) GitHub

Any Questions?

You can find us onDreamwidth, GitHub, and Twitter:

Jen Griffin ([email protected])Athena Yao ([email protected])

Thank you for coming!