コード例 #1
0
def sendStatistic(packages):
    types = {}

    for p in packages:
        for c in p.counters:
            if c.type not in types:
                types[c.type] = c

            types[c.type].add(c)

    for key in types:
        d = types[key]

        body = {
            "type": "jacoco_" + d.type,
            "data": {
                "missed": d.missed,
                "covered": d.covered
            }
        }

        api = client.Client()
        status = api.sendStatistic(body)
        print("[plugin-maven-test]: jacoco {} statistic data sent {}".format(
            d.type, status))
コード例 #2
0
def sendReport():
    if not os.path.exists(ReportPath):
        sys.exit("'{}' not existed".format(ReportPath))

    if not checkContentType(ReportContentType):
        sys.exit("Report content type not suported")

    upload = ReportPath
    isZipFile = "false"

    if os.path.isdir(ReportPath):
        zipFileName = os.path.basename(ReportPath)
        upload = shutil.make_archive(zipFileName, 'zip', ReportPath)
        isZipFile = "true"    
        print("zipped.")

    api = client.Client()

    status = api.sendJobReport(
        path=upload, 
        name=ReportName,
        zipped=isZipFile,
        contentType=ReportContentType,
        entryFile=EntryFile
    )

    print("{} report uploaded with status {}".format(ReportPath, status))
コード例 #3
0
def sendJobReport():
    reports = client.FindFiles("junit-report.html")

    if len(reports) == 0:
        print("[plugin-maven-test]: junit-report.html not found")
        return

    # copy resource to target
    outputDir = GetOutputDir()
    junitDir = os.path.join(outputDir, "junit")
    if os.path.exists(junitDir):
        shutil.rmtree(junitDir, True)
    os.mkdir(junitDir)

    junitResDir = os.path.join(os.path.dirname(os.path.dirname(__file__)),
                               "resources", "junit")
    shutil.copy(reports[0], junitDir)
    shutil.copytree(os.path.join(junitResDir, "css"),
                    os.path.join(junitDir, "css"))
    shutil.copytree(os.path.join(junitResDir, "images"),
                    os.path.join(junitDir, "images"))

    zipFile = os.path.join(outputDir, "junit-report")
    zipFile = shutil.make_archive(zipFile, 'zip', junitDir)

    api = client.Client()
    status = api.sendJobReport(path=zipFile,
                               name=domain.JobReportTests,
                               zipped="true",
                               contentType=domain.ContentTypeHtml,
                               entryFile="junit-report.html")
    print("[plugin-maven-test]: upload junit report with status {}".format(
        status))
    return
コード例 #4
0
def sendFlowStatistic(stats):
    body = {"type": "junit", "data": stats}

    api = client.Client()
    status = api.sendStatistic(body)
    print("[plugin-maven-test]: upload junit statistic data with status {}".
          format(status))
    return
コード例 #5
0
def sendReport(reports):
    outputDir = GetOutputDir()
    jacocoDir = os.path.join(outputDir, "jacoco")
    Merge(reports, jacocoDir)

    zipFile = os.path.join(outputDir, "jacoco-report")
    zipFile = shutil.make_archive(zipFile, 'zip', jacocoDir)

    api = client.Client()
    status = api.sendJobReport(path=zipFile,
                               name=domain.JobReportCodeCoverage,
                               zipped="true",
                               contentType=domain.ContentTypeHtml,
                               entryFile="index.html")

    print("[plugin-maven-test]: upload jacoco report with status {}".format(
        status))
コード例 #6
0
ファイル: report.py プロジェクト: flowci-plugins/npm-runner
def sendReport(path, entryFile):
    if not os.path.exists(path):
        print("'{}' not existed".format(path))
        return

    upload = path
    isZipFile = "false"

    if os.path.isdir(path):
        zipFileName = os.path.basename(path)
        upload = shutil.make_archive(zipFileName, 'zip', path)
        isZipFile = "true"
        print("zipped.")

    api = client.Client()

    status = api.sendJobReport(path=upload,
                               name=domain.JobReportCodeCoverage,
                               zipped=isZipFile,
                               contentType=domain.ContentTypeHtml,
                               entryFile=entryFile)

    print("{} report uploaded with status {}".format(path, status))
コード例 #7
0
ファイル: report.py プロジェクト: flowci-plugins/email-notify
def send():
    global ToAddr
    try:
        server = createServer()
        server.set_debuglevel(1)

        api = client.Client()

        if ToAddr == 'FLOW_USERS':
            users = api.listFlowUsers()
            emails = ''
            for user in users:
                emails += user['email'] + ","
            ToAddr = emails

        if SmtpUser != None:
            server.login(SmtpUser, SmtpPw)

        msg = createHtml()
        server.sendmail(from_addr=FromAddr, to_addrs=ToAddr.split(','), msg=msg.as_string())
        server.quit()
        print('[INFO] email been sent')
    except smtplib.SMTPException as e:
        print('[ERROR] on send email %s' % e)
コード例 #8
0
ファイル: report.py プロジェクト: flowci-plugins/email-notify
import smtplib
import sys
import os
from jinja2 import Template, Environment, FileSystemLoader
from flowci import client
from email import encoders
from email.header import Header
from email.mime.text import MIMEText
from email.utils import parseaddr, formataddr

SmtpConfig = client.GetVar('FLOWCI_SMTP_CONFIG')
FromAddr = client.GetVar('FLOWCI_EMAIL_FROM')
ToAddr = client.GetVar('FLOWCI_EMAIL_TO')


API = client.Client()
Config = API.getConfig(SmtpConfig)

if Config == None:
    sys.exit('Cannot get smtp config')

if Config['category'] != 'SMTP':
    sys.exit('Invalid SMTP config')

SmtpSecure = Config['secure']  # NONE, SSL, TLS
SmtpAddr = Config['server']
SmtpPort = Config['port']
SmtpUser = Config['auth']['username']
SmtpPw = Config['auth']['password']

def createServer():
コード例 #9
0
ファイル: gitclone.py プロジェクト: flowci-plugins/gitclone
def gitPullOrClone():
    dest = os.path.join(domain.AgentJobDir, GitRepoName)
    api = client.Client()

    # load credential
    if CredentialName is not None:
        c = api.getCredential(CredentialName)
        setupCredential(c)

    # clean up
    if os.path.exists(dest):
        try:
            shutil.rmtree(dest)
        except OSError as e:
            print("[ERROR]: %s - %s." % (e.filename, e.strerror))

        # repo = Repo(dest)
        # repo.remote().pull(progress = MyProgressPrinter())

    # git clone
    env = {}
    if KeyPath is not None:
        env["GIT_SSH_COMMAND"] = 'ssh -o {} -o {} -i {}'.format(
            'UserKnownHostsFile=/dev/null', 'StrictHostKeyChecking=no', KeyPath)

    branchOrCommit = GitBranch
    if GitCommitId != None:
        branchOrCommit = GitCommitId

    if branchOrCommit == None:
        sys.exit("FLOWCI_GIT_BRANCH or FLOWCI_GIT_COMMIT_ID must be defined")

    try:
        repo = Repo.init(dest)
        repo.create_remote('origin', url=GitUrl)
        repo.remotes.origin.fetch(branchOrCommit, progress=MyProgressPrinter(), env=env)
        repo.git.checkout(branchOrCommit)

        head = repo.head
        if head != None and head.commit != None:
            sha = head.commit.hexsha
            message = head.commit.message
            dt = head.commit.committed_datetime
            email = head.commit.author.email
            name = head.commit.author.name

            commitList = [
                {
                    'id': sha,
                    'message': message,
                    'time': dt.strftime('%Y-%m-%d %H:%M:%S'),
                    'author': {
                        'name': name,
                        'email': email
                    }
                }
            ]

            api.addJobContext({
                VarCommitID: sha,
                VarCommitMessage: message,
                VarCommitTotal: 1,
                VarCommitList: str(base64.b64encode(json.dumps(commitList).encode("utf-8")), "utf-8")
            })

        output = repo.git.submodule('update', '--init')
        print(output)

        put(0, '')
        ExitEvent.set()
    except Exception as e:
        put(1, 'Failed to clone git repo: ' + str(e))
        ExitEvent.set()
コード例 #10
0
import os
import sys
import getopt
from flowci import client

api = client.Client()
uploaded = set()

def startFromInput(path):
    for line in path.splitlines():
        for item in line.split(";"):
            if item == '' or not os.path.exists(item):
                log("path or file '%s' not found" % item)
                continue

            if os.path.isfile(item):
                uploadFile(item)
                continue

            if os.path.isdir(item):
                uploadDir(item)


def uploadFile(path, srcDir = None):
    if path in uploaded:
        return

    uploaded.add(path)
    log("file '%s' will be loaded.." % path)
    r = api.uploadJobArtifact(path, srcDir)
    log("upload status is %s" % r)