(errMsg, excMsg)
Automatically create a Github issue with unhandled exception information
Automatically create a Github issue with unhandled exception information
Automatically create a Github issue with unhandled exception information
def createGithubIssue(errMsg, excMsg):
    """
    Automatically create a Github issue with unhandled exception information
    """

    issues = []
    try:
        issues = getFileItems(paths.GITHUB_HISTORY, unique=True)
    except:
        pass
    finally:
        issues = set(issues)

    _ = re.sub(r"'[^']+'", "''", excMsg)
    _ = re.sub(r"\s+line \d+", "", _)
    _ = re.sub(r'File ".+?/(\w+\.py)', "\g<1>", _)
    _ = re.sub(r".+\Z", "", _)
    key = hashlib.md5(_).hexdigest()[:8]

    if key in issues:
        return

    msg = "\ndo you want to automatically create a new (anonymized) issue "
    msg += "with the unhandled exception information at "
    msg += "the official Github repository? [y/N] "
    try:
        test = readInput(msg, default="N")
    except:
        test = None

    if test and test[0] in ("y", "Y"):
        ex = None
        errMsg = errMsg[errMsg.find("\n"):]


        data = {"title": "Unhandled exception (#%s)" % key, "body": "```%s\n```\n```\n%s```" % (errMsg, excMsg)}
        req = urllib2.Request(url="https://api.github.com/repos/sqlmapproject/sqlmap/issues", data=json.dumps(data), headers={"Authorization": "token %s" % GITHUB_REPORT_OAUTH_TOKEN.decode("base64")})

        try:
            f = urllib2.urlopen(req)
            content = f.read()
        except Exception, ex:
            content = None

        issueUrl = re.search(r"https://github.com/sqlmapproject/sqlmap/issues/\d+", content or "")
        if issueUrl:
            infoMsg = "created Github issue can been found at the address '%s'" % issueUrl.group(0)
            logger.info(infoMsg)

            try:
                with open(paths.GITHUB_HISTORY, "a+b") as f:
                    f.write("%s\n" % key)
            except:
                pass
        else:
            warnMsg = "something went wrong while creating a Github issue"
            if ex:
                warnMsg += " ('%s')" % getSafeExString(ex)
            if "Unauthorized" in warnMsg:
                warnMsg += ". Please update to the latest revision"
            logger.warn(warnMsg)
def createGithubIssue ( errMsg , excMsg ) : issues = [ ] try : issues = getFileItems ( paths . GITHUB_HISTORY , unique = True ) except : pass finally : issues = set ( issues ) _ = re . sub ( r"'[^']+'" , "''" , excMsg ) _ = re . sub ( r"\s+line \d+" , "" , _ ) _ = re . sub ( r'File ".+?/(\w+\.py)' , "\g<1>" , _ ) _ = re . sub ( r".+\Z" , "" , _ ) key = hashlib . md5 ( _ ) . hexdigest ( ) [ : 8 ] if key in issues : return msg = "\ndo you want to automatically create a new (anonymized) issue " msg += "with the unhandled exception information at " msg += "the official Github repository? [y/N] " try : test = readInput ( msg , default = "N" ) except : test = None if test and test [ 0 ] in ( "y" , "Y" ) : ex = None errMsg = errMsg [ errMsg . find ( "\n" ) : ] data = { "title" : "Unhandled exception (#%s)" % key , "body" : "```%s\n```\n```\n%s```" % ( errMsg , excMsg ) } req = urllib2 . Request ( url = "https://api.github.com/repos/sqlmapproject/sqlmap/issues" , data = json . dumps ( data ) , headers = { "Authorization" : "token %s" % GITHUB_REPORT_OAUTH_TOKEN . decode ( "base64" ) } ) try : f = urllib2 . urlopen ( req ) content = f . read ( ) except Exception , ex : content = None issueUrl = re . search ( r"https://github.com/sqlmapproject/sqlmap/issues/\d+" , content or "" ) if issueUrl : infoMsg = "created Github issue can been found at the address '%s'" % issueUrl . group ( 0 ) logger . info ( infoMsg ) try : with open ( paths . GITHUB_HISTORY , "a+b" ) as f : f . write ( "%s\n" % key ) except : pass else : warnMsg = "something went wrong while creating a Github issue" if ex : warnMsg += " ('%s')" % getSafeExString ( ex ) if "Unauthorized" in warnMsg : warnMsg += ". Please update to the latest revision" logger . warn ( warnMsg )