GithubHelp home page GithubHelp logo

tomgarden / tomgitactions Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 3.67 MB

通过 GitHub action 维护的 issues Blog

Home Page: https://github.com/TomGarden/TomGitActions/issues/45

Python 95.04% Dockerfile 1.25% Shell 3.70%
github-actions issues-blog

tomgitactions's People

Contributors

tomgarden avatar

Stargazers

 avatar

Watchers

 avatar

tomgitactions's Issues

README.md

我是页眉


正则匹配链接[]()语法上有局限性 , 如有疑虑可查看本文原文

又到了夏天, 蝉又要叫了

0x00. 做了一个什么?

一个个人博客程序 : 通过 github actions 将 github repository 中的 markdown 文件发布到该 repository 的 issues 中 .

抄自 : https://github.com/Sep0lkit/git-issues-blog

0x01. 局限性

1.1. markdown 链接语法替换问题

对 markdown 中的链接语法 [](http 巴拉巴拉) 支持的不够完善 .

当前是通过 EL(Expression Language) 表达式完成的匹配与替换

# 甚至在我贴出这段代码的时候我都在担心这段代码会把我贴出的这段代码给替换的啥都不是了 , 细想了一下发现没问题 😁
# 局限性的问题的一个表现就是还需要想一下

def replace_markdown_links(input_str: str, path: str) -> str:
    pattern = r'\[(.*?)\]\((?!http)(.*?)\)'
    re_format = "[\\1](https://raw.githubusercontent.com/{}/{}/{}/\\2)".format(
        GITHUB_REPO, GITHUB_BRANCH, path)
    result = re.sub(pattern, re_format, input_str, flags=re.M)
    return result

关于这个规则如果看到的你有更好的改进方案 , 我很乐意修正这个实现细节

1.2. git 文件变化识别问题

class ModifyEnum(enum.Enum):
    """
    规范: https://git-scm.com/docs/git-diff#Documentation/git-diff.txt-git-diff-filesltpatterngt82308203

    下述修改我们
        知道怎么触发的标记为 [√]
        不知道怎么触发的标记为 [x] //未成功测试处理的修改类型, 通过 git diff 文档给定的格式进行操作

    [√] A: addition of a file
    [x] C: copy of a file into a new one
    [√] D: deletion of a file
    [√] M: modification of the contents or mode of a file
    [√] R: renaming of a file
    [x] T: change in the type of the file
    [x] U: file is unmerged (you must complete the merge before it can be committed)
    [x] X: "unknown" change type (most probably a bug, please report it)
    """
    modify_addition = 'A'
    modify_copy = 'C'
    modify_deletion = 'D'
    modify_modification = 'M'
    modify_renaming = 'R'
    modify_file_is_unmerged = 'U'

    modify_change_type = 'T'
    modify_unknown = 'X'

0x02. 文件内容

如果想查看实现细节或者自己有兴趣实现一次 , .github 文件中留有各种文件和说明

0x03. 关于使用方式

我看是有简单的给人用的方式的, 我还没学会, 又不想学了, 但是现在简单的方式又不够优雅, 真实矛盾:

  1. clone repository , 将 .github 文件拷贝到自己 repository
  2. 在自己的项目手动创建一个 issue , 可以有标题, 内容一定要为空, 就是没有内容
    • 当然也可以是有内容的, 前提是你得知道自己在做什么
    • 把这个 issue 的 id (就是从 1 开始计数的那个数字)放到这里:
      • .github/workflows/github_host.yml 文件的 ISSUES_MAP_FILE_NUMBER: '9'
  3. 阅读此文件注释 .github/github_actions/issues_config.json
  4. 至此已经可以是用了
  5. 关于其他配置细节
    • ISSUES_FOOTER_PATH: '.github/github_actions/issues_footer.md'
    • ISSUES_HEADER_PATH: '.github/github_actions/issues_header.md'

0x04. 实现细节

4.1. 主流程

  1. 全程 yml 居中调度
  2. install_dependence_xxx.sh 安装依赖 (python . 等)
  3. git_action_practice.py 实现从 repository 到 issue 的负值粘贴

4.2. git_action_practice.py细节

  1. 通过 pygithubrequsts 调用 github api
    实现 repository 文件的拉取 和 issues 内容的上传
  2. 通过 git log 获取仓库变化时间和 哈希
  3. 通过 git diff 根据按仓库变化的 哈希 获取变化的文件路径和
  4. 维护一个 repository : issue 的文件映射持久化到 一个指定的 issue 中(json 格式) .
    这个文件也记录上次成功执行的 commit hash
  5. DONE

0x06. 其他内容

证明文件链接有一定可用性

证明图片链接有一定可用性

  • 截图一张

我是页脚

映射文件

{
  "last_success_opt_commit_log_line_key": "767ba8db9cbb98f37fec291ce9abb09cb0ff77d9···@/@···2020-05-31 12:45:43 +0800···@/@···开放私钥 debug 文件, 并删除 私钥",
  "issues_dictionary_map_key": {
    ".github/github_actions/test2.py": 32,
    ".github/github_actions/test_python.py": 33,
    "README.md": 45
  }
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.