<s> import hashlib , api <EOL> from django . conf import settings <EOL> class GitlabIssuesHelper ( object ) : <EOL> """<STR_LIT>""" <EOL> @ staticmethod <EOL> def __trace_checksum ( trace ) : <EOL> """<STR_LIT>""" <EOL> return hashlib . sha1 ( trace ) . hexdigest ( ) <EOL> @ classmethod <EOL> def store_issue ( _class , trace , project_id , issue_id ) : <EOL> """<STR_LIT>""" <EOL> from models import History <EOL> history , created = History . objects . get_or_create ( <EOL> checksum = _class . __trace_checksum ( trace ) , <EOL> defaults = { <EOL> '<STR_LIT>' : project_id , <EOL> '<STR_LIT>' : issue_id , <EOL> } , <EOL> ) <EOL> if not created : <EOL> history . project_id = project_id <EOL> history . issue_id = issue_id <EOL> history . save ( ) <EOL> @ classmethod <EOL> def check_issue ( _class , project_id , trace ) : <EOL> """<STR_LIT>""" <EOL> from models import History <EOL> exists , issue_id = False , None <EOL> checksum = _class . __trace_checksum ( trace ) <EOL> try : <EOL> history = History . objects . get ( project_id = project_id , checksum = checksum ) <EOL> exists , issue_id = True , history . issue_id <EOL> except History . DoesNotExist : <EOL> pass <EOL> return exists , issue_id <EOL> @ staticmethod <EOL> def gitlab ( ) : <EOL> """<STR_LIT>""" <EOL> return api . Gitlab ( settings . GITLAB_HOST , settings . GITLAB_USER , token = settings . GITLAB_TOKEN ) </s>
