Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nix flake init #6

Merged
merged 2 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

use flake
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
node_modules
dist
.pre-commit-config.yaml
.direnv
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
### How this works

With Github API:
get pr merged commit hash -> compare target branch HEAD ... commit -> get status
get pr merged commit hash -> compare target branch HEAD ... commit -> get status

nixpkgs-tracker not same as [nixpk.gs/pr-tracker](https://nixpk.gs/pr-tracker.html),
it does not pass any requests through server to get PR status.
Expand All @@ -14,7 +14,6 @@ Therefore, there is no need to worry about any performance issues.
- [x] Stable link (e.g. https://nixpkgs-tracker.ocfox.me/?pr=331928)
- [x] Github token for more requests limit (Cookie) (optional)
- [x] Click `Nixpkgs-Tracker` to switch light / dark
- [x] Check 5 branches at the same time
- [x] Check 5 branches at the same time

<img width="1552" alt="image" src="https://github.com/user-attachments/assets/d247eb27-0320-4384-ad3f-36daca4d0ac0">

102 changes: 102 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

65 changes: 65 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";

treefmt-nix.url = "github:numtide/treefmt-nix";
treefmt-nix.inputs.nixpkgs.follows = "nixpkgs";

git-hooks = {
url = "github:cachix/git-hooks.nix";
inputs.nixpkgs.follows = "nixpkgs";
inputs.nixpkgs-stable.follows = "";
};
};

outputs =
{
self,
nixpkgs,
treefmt-nix,
git-hooks,
...
}:
let
system = "x86_64-linux";
pkgs = import nixpkgs { inherit system; };
treefmtCfg = (treefmt-nix.lib.evalModule pkgs ./treefmt.nix).config.build;
in
rec {
formatter.${system} = treefmtCfg.wrapper;
checks.${system} = {
formatting = treefmtCfg.check self;
git-hooks-check = git-hooks.lib.${system}.run {
src = ./.;
hooks = {
deadnix = {
enable = true;
stages = [ "pre-push" ];
};
statix = {
enable = true;
stages = [ "pre-push" ];
};
nixfmt = {
package = pkgs.nixfmt-rfc-style;
enable = true;
stages = [
"pre-push"
"pre-commit"
];
};
};
};
};
devShells.${system}.default = pkgs.mkShellNoCC {
inherit (self.checks.${system}.git-hooks-check) shellHook;
buildInputs = self.checks.${system}.git-hooks-check.enabledPackages;
packages =
[ pkgs.yarn ]
++ [
treefmtCfg.wrapper
(pkgs.lib.attrValues treefmtCfg.programs)
];
};
};
}
4 changes: 4 additions & 0 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
let
pkgs = import <nixpkgs> { };
in
pkgs.mkShellNoCC { packages = [ pkgs.yarn ]; }
6 changes: 3 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import "./style.css";
import setupColorScheme from "./scheme.ts";
import {
branches,
isContain,
getMeregeCommit,
getPR,
hasToken,
isContain,
setToken,
getMeregeCommit,
} from "./utils.ts";

document.querySelector<HTMLDivElement>("#app")!.innerHTML = `
Expand Down Expand Up @@ -135,7 +135,7 @@ async function handlePR(pr: string) {
async function checkBranch(branch: string) {
const merged = await isContain(branch, mergeCommit);
const branchElement = document.querySelector<HTMLHeadingElement>(
`#${branch}`
`#${branch}`,
)!;
if (merged) {
branchElement.textContent = `${branch} ✅`;
Expand Down
6 changes: 3 additions & 3 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type PR = {
export async function getPR(pr: string): Promise<PR> {
const response = await fetch(
`https://api.github.com/repos/nixos/nixpkgs/pulls/${pr}`,
{ headers }
{ headers },
);

const data = await response.json();
Expand All @@ -51,7 +51,7 @@ export async function getPR(pr: string): Promise<PR> {
export async function getMeregeCommit(pr: string): Promise<string> {
const response = await fetch(
`https://api.github.com/repos/nixos/nixpkgs/pulls/${pr}`,
{ headers }
{ headers },
);

const data = await response.json();
Expand All @@ -61,7 +61,7 @@ export async function getMeregeCommit(pr: string): Promise<string> {

export async function isContain(
branch: string,
commit: string
commit: string,
): Promise<boolean> {
const url = `https://api.github.com/repos/nixos/nixpkgs/compare/${branch}...${commit}`;
const response = await fetch(url, { headers });
Expand Down
10 changes: 10 additions & 0 deletions treefmt.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
_: {
projectRootFile = "flake.nix";

programs = {
nixfmt.enable = true;
deadnix.enable = true;
statix.enable = true;
prettier.enable = true;
};
}