Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
HerrCai0907 authored and actions-user committed Apr 15, 2024
0 parents commit 213049f
Show file tree
Hide file tree
Showing 17 changed files with 1,229 additions and 0 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/fetch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
name: Build
on:
push:
branches:
- dev
schedule:
- cron: "0 2 * * 1"
workflow_dispatch:

jobs:
build:
name: "update contribution"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: dev

- uses: actions/setup-node@v3
with:
node-version: "20"
- run: npm ci

- name: Set up repository
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git config user.name "GitHub Actions"
git config user.email "actions@github.com"
git remote set-url origin "https://${GITHUB_ACTOR}:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git"
git fetch origin
if [ -z "$GITHUB_HEAD_REF" ]; then
# If not a PR, undo detached head
git checkout "${GITHUB_REF:11}"
fi
- name: "Generate SVG"
run: node fetcher
env:
TOKEN: ${{ secrets.FETCH_GITHUB_TOKEN }}

- name: "Push changes to GitHub"
run: |
git add ./fetcher/lang.svg
git commit --amend -m "update"
git push --force -u origin HEAD:main
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/node_modules
/.vscode
23 changes: 23 additions & 0 deletions Autosar_Logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added LLVM_logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Hi there 👋

## About me

- I am an Automotive Software Development Engineer in China 🇨🇳.
- I use C++ and TypeScript as my major development languages.
- I am interested in runtime, compiler and language tooling related development.
- [Assemblyscript](https://github.com/AssemblyScript/assemblyscript)
- [LLVM](https://github.com/llvm/llvm-project)

## My Technical Stack

<img src="./cpp_Logo.png" height = "25"/> <img src="./Typescript.png" height = "25"/> <img src="./assemblyscript.svg" height = "25"/> <img src="./WebAssembly.png" height = "25"/> <img src="./LLVM_logo.png" height = "25"/> <img src="./Autosar_Logo.svg" height = "25"/> <img src="./bazel.svg" height = "25"/>

## My Github

![Top Langs](./fetcher/lang.svg)
Binary file added Typescript.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added WebAssembly.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions assemblyscript.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions bazel.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added cpp_Logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions fetcher/analysis.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import languages from "linguist-languages";

export function top(info, num) {
let sum = 0;
let data = [];
for (const lang in info) {
const line = info[lang];
sum += line;
}

console.log("statistic result :\n", info);

for (const lang in info) {
const line = info[lang];
data.push({ lang, rate: (line / sum) * 100, color: languages[lang].color });
}
data.sort((a, b) => b.rate - a.rate);

console.log("statistic result :\n", data);

return data.slice(0, num);
}
143 changes: 143 additions & 0 deletions fetcher/draw.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
import { writeFileSync } from "fs";

function drawItem(topItem, index) {
return `
<g transform="translate(0, ${0 + index * 40})">
<g class="stagger" style="animation-delay: ${450 + 150 * index}ms">
<text data-testid="lang-name" x="2" y="15" class="lang-name">${topItem.lang}</text>
<text x="215" y="34" class="lang-name">${topItem.rate.toFixed(2)}%</text>
<svg width="205" x="0" y="25">
<rect rx="5" ry="5" x="0" y="0" width="205" height="8" fill="#ddd"></rect>
<svg data-testid="lang-progress" width="${topItem.rate.toFixed(2)}%">
<rect height="8" fill="${topItem.color}" rx="5" ry="5" x="0" y="0" class="lang-progress"
style="animation-delay: ${750 + 150 * index}ms;" />
</svg>
</svg>
</g>
</g>
`;
}

export function draw(topInfo) {
const len = topInfo.length;
const width = len * 40 + 85;

const svg = `
<svg width="300" height="${width}" viewBox="0 0 300 ${width}" fill="none" xmlns="http://www.w3.org/2000/svg" role="img"
aria-labelledby="descId">
<title id="titleId"></title>
<desc id="descId"></desc>
<style>
.header {
font: 600 18px 'Segoe UI', Ubuntu, Sans-Serif;
fill: #fe428e;
animation: fadeInAnimation 0.8s ease-in-out forwards;
}
@supports(-moz-appearance: auto) {
/* Selector detects Firefox */
.header {
font-size: 15.5px;
}
}
@keyframes slideInAnimation {
from {
width: 0;
}
to {
width: calc(100%-100px);
}
}
@keyframes growWidthAnimation {
from {
width: 0;
}
to {
width: 100%;
}
}
.stat {
font: 600 14px 'Segoe UI', Ubuntu, "Helvetica Neue", Sans-Serif;
fill: #a9fef7;
}
@supports(-moz-appearance: auto) {
/* Selector detects Firefox */
.stat {
font-size: 12px;
}
}
.bold {
font-weight: 700
}
.lang-name {
font: 400 11px "Segoe UI", Ubuntu, Sans-Serif;
fill: #a9fef7;
}
.stagger {
opacity: 0;
animation: fadeInAnimation 0.3s ease-in-out forwards;
}
#rect-mask rect {
animation: slideInAnimation 1s ease-in-out forwards;
}
.lang-progress {
animation: growWidthAnimation 0.6s ease-in-out forwards;
}
/* Animations */
@keyframes scaleInAnimation {
from {
transform: translate(-5px, 5px) scale(0);
}
to {
transform: translate(-5px, 5px) scale(1);
}
}
@keyframes fadeInAnimation {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
</style>
<rect data-testid="card-bg" x="0.5" y="0.5" rx="4.5" height="99%" stroke="#e4e2e2" width="299" fill="#141321"
stroke-opacity="1" />
<g data-testid="card-title" transform="translate(25, 35)">
<g transform="translate(0, 0)">
<text x="0" y="0" class="header" data-testid="header">Most Used Languages</text>
</g>
</g>
<g data-testid="main-card-body" transform="translate(0, 55)">
<svg data-testid="lang-items" x="25">
${topInfo.map((item, index) => drawItem(item, index)).join("\n")}
</svg>
</g>
</svg>
`;

writeFileSync("fetcher/lang.svg", svg);
}
77 changes: 77 additions & 0 deletions fetcher/fetcher.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { Octokit } from "@octokit/core";
import { env } from "process";
import languages from "linguist-languages";
import { basename, extname } from "path";

const orgs = ["HerrCai0907", "Schleifner", "assemblyscript", "nodejs", "WebAssembly", "MaaAssistantArknights"];
const repos = ["llvm/llvm-project"];
const ignoreLanguages = ["WebAssembly"];

function prepareQuery() {
const projectRanges = orgs.map((v) => `org:${v}`).join(" ") + " " + repos.map((v) => `repo:${v}`).join(" ");
const startDate = new Date(Date.now() - 30 * 24 * 60 * 60 * 1000);
return encodeURIComponent(`author:HerrCai0907 ${projectRanges} committer-date:>${startDate.toISOString()}`);
}

const result = {};

function statistic(file, lines) {
const ext = extname(file);
(() => {
for (let lang of Object.keys(languages)) {
if (!languages[lang].color) continue;
if (languages[lang].filenames?.includes(basename(file))) {
result[lang] = result[lang] ?? 0;
result[lang] += lines;
console.log(`add '${lang}' ${lines} lines due to '${file}'`);
return;
}
}
for (let lang of Object.keys(languages)) {
if (!languages[lang].color) continue;
if (languages[lang].extensions?.includes(ext)) {
result[lang] = result[lang] ?? 0;
result[lang] += lines;
console.log(`add '${lang}' ${lines} lines due to '${file}'`);
return;
}
}
})();
}

export async function fetchFromGithub() {
const octokit = new Octokit({
auth: env["TOKEN"],
});

const request = `GET /search/commits?q=${prepareQuery()}`;

console.log(`fetch ${request}`);

for (let pageIndex = 0; ; pageIndex++) {
const {
data: { items },
} = await octokit.request(request, {
headers: { "X-GitHub-Api-Version": "2022-11-28" },
per_page: 100,
page: pageIndex,
});

if (items.length == 0) {
break;
}
await Promise.all(
items.map(async (item) => {
console.log(`fetch ${item.url}`);
const { data } = await octokit.request(item.url);
data.files.forEach((file) => {
statistic(file.filename, file.changes);
});
})
);
}
for (let lang of ignoreLanguages) {
delete result[lang];
}
return result;
}
5 changes: 5 additions & 0 deletions fetcher/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { fetchFromGithub } from "./fetcher.js";
import { top } from "./analysis.js";
import { draw } from "./draw.js";

draw(top(await fetchFromGithub(), 5));
Loading

0 comments on commit 213049f

Please sign in to comment.