예제 #1
0
파일: utils.py 프로젝트: PengboBai/script
def call(cmd):
    logs.info("Exec cmd: %s" % cmd)
    status, output = subprocess.getstatusoutput(cmd)
    if status:
        logs.error(output)
        raise Exception("Exec cmd fail, cmd: %s" % cmd)
    return output
예제 #2
0
 def __update_code(self):
     """
     update repo code and merge tag
     """
     logs.info("BRANCH: %s" % self.branch)
     logs.info("USRE_NAME: %s" % self.user_name)
     utils.mkdirs(self.code_path)
     utils.clone_repo(self.repo_path, self.repo_uri)
     os.chdir(self.repo_path)
     cmd_list = [
         'git clean -df',
         'git reset --hard',
         'git branch | grep "\* {branch}" || git checkout {branch}'.format(
             branch=self.branch),
         'git fetch',
         'git reset --hard origin/{branch}'.format(branch=self.branch),
         'git remote remove STAGE || echo "del stage remote"',
         'git remote add STAGE {stage_uri}'.format(
             stage_uri=self.stage_uri),
         'git fetch STAGE tag phabricator/diff/{diff}'.format(
             diff=self.diff),
         'git merge phabricator/diff/{diff}'.format(diff=self.diff),
     ]
     try:
         for cmd in cmd_list:
             utils.call(cmd)
     except Exception as e:
         logs.error(e)
         raise Exception("Merge tag fail" if "git merge" in
                         str(e) else "Update code fail")
예제 #3
0
파일: build.py 프로젝트: PengboBai/script
 def __run_build(self):
     # dry run
     q = differential.Query(self.diff, self.revision)
     statust = q.get_revision_status()
     logs.info("Revision status: %s" % statust)
     if str(statust) in ["3", "4"]:
         logs.warning("Revision was Closed or Abandoned")
         sys.exit(2)
     # TODO do other build
     diffs = q.get_diffs()
     if 2 > len(diffs):
         # set build result "fail"
         self.build_status = 1
     logs.info("Build status: %s" % self.build_status)
예제 #4
0
파일: build.py 프로젝트: PengboBai/script
 def __feedback(self):
     revision_edit = differential.RevisionEdit(self.diff, self.revision)
     revision_edit.remove_reviewer()
     if self.build_status:
         revision_edit.add_reviewer()
         revision_edit.set_revision_status("reject")
     title_msg = "IMPORTANT: build fail" if self.build_status else "NOTE: build pass"
     logs.info("Title msg: %s" % title_msg)
     table_msg = """| Build | Klockworks | Coverity | UT/FT 
                    | ----- | ----- | ----- | ----- 
                    | {iconfont} | {iconfont} | {iconfont} | {iconfont} 
                    | [[{url} | Link]] | [[{url} | Link]] | [[{url} | Link]] | [[{url} | Link]] 
                 """.format(
         iconfont='{icon times color=red}'
         if self.build_status else '{icon check color=green}',
         url=self.jenkinks_url)
     revision_edit.feedback(title_msg + "\n\n" + table_msg)
     logs.info(table_msg)
예제 #5
0
            }]
        }
        self.conduit.call_api(self.method, params)

    def add_reviewer(self, reviewer_phid=config.PHA_CONFIG["BOT_PHID"]):
        params = {
            "objectIdentifier": self.revision,
            "transactions": [{
                "type": "reviewers.add",
                "value": [reviewer_phid]
            }]
        }
        self.conduit.call_api(self.method, params)

    def set_revision_status(self, action):
        """
        reject: can not arc land
        """
        params = {
            "objectIdentifier": self.revision,
            "transactions": [{
                "type": action
            }]
        }
        self.conduit.call_api(self.method, params)


if __name__ == "__main__":
    query_diff = QueryDiffs('1', '1')
    logs.info(query_diff.get_user_name())
예제 #6
0
        ]
        try:
            for cmd in cmd_list:
                utils.call(cmd)
        except Exception as e:
            logs.error(e)
            raise Exception("Merge tag fail" if "git merge" in
                            str(e) else "Update code fail")

    def exec_update(self):
        try:
            self.__update_code()
        except Exception as e:
            self.qd.feedback("IMPORTANT: %s" % str(e))
            # TODO update db
            # exit code
            # 1 set job FAILURE, env error
            # 2 set job UNSTABLE, merge fails
            sys.exit(2 if "Merge tag fail" in str(e) else 1)


if __name__ == "__main__":
    parser = argparse.ArgumentParser(description='Script for update code')
    parser.add_argument('revision', help='revision id')
    parser.add_argument('diff', help='diff id')
    parser.add_argument('repo_uri', help='repo uri')
    parser.add_argument('stage_uri', help='stage uri')
    args = parser.parse_args()
    logs.info(args)
    update = Update(args.revision, args.diff, args.repo_uri, args.stage_uri)
    update.exec_update()
예제 #7
0
        #     "transactions": [{"type": "reviewers.remove", "value": [reviewer_phid]}]
        # }
        data = {'api.token': self.api_token}
        for name, value in params.items():
            if isinstance(value, list):
                for i in range(len(value)):
                    if isinstance(value[i], dict):
                        for key, info in value[i].items():
                            if isinstance(info, list):
                                for info_index, info_value in enumerate(info):
                                    data["{name}[{index}][{key}][{info_index}]".format(
                                        name=name, index=i, key=key, info_index=info_index)] = info_value
                            else:
                                data["{name}[{index}][{key}]".format(name=name, index=i, key=key)] = info
                    else:
                        data["{name}[{index}]".format(name=name, index=i)] = value[i]
            else:
                data[name] = value
        logs.debug("Format conduit data: %s" % data)
        return data


if __name__ == "__main__":
    conduit = Conduit()
    # conduit.call_api("differential.revision.edit", {"objectIdentifier": 1,
    #                                                 "transactions": [{"type": "title", "value": "test title"},
    #                                                                  {"type": "testPlan", "value": "no"}]})
    # conduit.call_api("differential.close", {"revisionID": 1})
    result = conduit.call_api("differential.querydiffs", {"ids[0]": 1})
    logs.info(result)
예제 #8
0
파일: entry.py 프로젝트: PengboBai/script
 def __record_data(self):
     logs.info("Record data to database")