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

Main2 #23

Closed
wants to merge 7 commits into from
Closed
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
Original file line number Diff line number Diff line change
@@ -1,43 +1,41 @@
package main

package funcs

Check failure on line 1 in src/funcs/create_character_img.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gofmt`-ed with `-s` (gofmt)

Check failure on line 1 in src/funcs/create_character_img.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gofmt`-ed with `-s` (gofmt)
import (
"fmt"

"github.com/tomoish/readme/funcs"
)

func CreateCharacterImg() {
// キャラクター画像のパス
characterPath := "funcs/images/character.png"
characterPath := "images/character.png"
// ゲージ画像のパス
gaugePath := "funcs/images/gauge.png"
gaugePath := "images/gauge.png"

// ゲージ画像生成のためのチャネル
gaugeImageChan := make(chan []byte)

// ゲージ画像を非同期で生成
go func() {
GaugeBytes, _ := funcs.DrawGauge(0.5)
GaugeBytes, _ := DrawGauge(0.5)
gaugeImageChan <- GaugeBytes
}()

// ゲージ画像をファイルに保存
gaugeBytes := <-gaugeImageChan
err := funcs.SaveImage(gaugePath, gaugeBytes)
err := SaveImage(gaugePath, gaugeBytes)
if err != nil {
fmt.Println(err)
return
}

// キャラクター画像とゲージ画像を合成
mergedImage, err := funcs.MergeImages(characterPath, gaugePath)
mergedImage, err := MergeImages(characterPath, gaugePath)
if err != nil {
fmt.Println(err)
return
}

// 画像をファイルに保存
err = funcs.SaveImage("funcs/images/merged.png", mergedImage)
err = SaveImage("images/merged.png", mergedImage)
if err != nil {
fmt.Println(err)
return
Expand Down
23 changes: 12 additions & 11 deletions src/create_language_img.go → src/funcs/create_language_img.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package main
package funcs

import (
"fmt"
"time"

"github.com/patrickmn/go-cache"

Check failure on line 8 in src/funcs/create_language_img.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gofmt`-ed with `-s` (gofmt)

Check failure on line 8 in src/funcs/create_language_img.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gofmt`-ed with `-s` (gofmt)
"github.com/tomoish/readme/funcs"
)

func CreateLanguageImg() {

// 言語ごとの色をここで決める
colordict := map[string]string{
"HTML": "#E34F26",
"CSS": "#ffffff",
Expand All @@ -30,7 +29,7 @@
// キャッシュにデータが存在しない場合のみデータを保存
if _, found := c.Get(key); !found {
// トークンを取得する
token, newCachedData = funcs.GetTokens(0)
token, newCachedData = GetTokens(0)

c.Set(key, newCachedData, cache.DefaultExpiration)
} else {
Expand All @@ -42,7 +41,7 @@
fmt.Println("cachedIntData")
fmt.Println(cachedIntData)
// トークンを取得する
token, newCachedData = funcs.GetTokens(cachedIntData)
token, newCachedData = GetTokens(cachedIntData)

c.Set(key, newCachedData, cache.DefaultExpiration)

Expand All @@ -51,7 +50,7 @@

// ユーザーのリポジトリ情報を取得
username := "kou7306"
repos, err := funcs.GetRepositories(username, token)
repos, err := GetRepositories(username, token)
fmt.Printf("repos: %v\n", repos)
if err != nil {
fmt.Println(err)
Expand All @@ -64,7 +63,7 @@

// 各リポジトリの言語別のファイルサイズを取得
for _, repo := range repos {
repoDetails, totalSize, err := funcs.GetRepositoryLanguage(repo.Name, repo.Owner, token)
repoDetails, totalSize, err := GetRepositoryLanguage(repo.Name, repo.Owner, token)

if err != nil {
// エラーハンドリング
Expand All @@ -82,7 +81,7 @@
}
colorCode := ""

languages := []funcs.LanguageStat{}
languages := []LanguageStat{}
// 各言語のファイルサイズをパーセンテージで計算
for language, size := range totalLanguageSize {
percentage := float64(size) / allSize * 100.0
Expand All @@ -96,7 +95,7 @@
colorCode = colordict["others"]
}

languages = append(languages, funcs.LanguageStat{
languages = append(languages, LanguageStat{
Name: language,
Percent: percentage,
Color: colorCode,
Expand All @@ -105,14 +104,16 @@

fmt.Printf("languages: %v\n", languages)

ImgBytes, _ := funcs.GenerateLanguageUsageGraph(languages, 600, 250)
ImgBytes, _ := GenerateLanguageUsageGraph(languages, 600, 250)

// 画像をファイルに保存
err = funcs.SaveImage("funcs/images/language.png", ImgBytes)
err = SaveImage("images/language.png", ImgBytes)
if err != nil {
fmt.Println(err)
}

// return languages

}

// func generateSessionKey() string {
Expand Down
123 changes: 123 additions & 0 deletions src/funcs/get_activity.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
package funcs

import (
"bytes"
"fmt"

Check failure on line 5 in src/funcs/get_activity.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gofmt`-ed with `-s` (gofmt)

Check failure on line 5 in src/funcs/get_activity.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gofmt`-ed with `-s` (gofmt)
"encoding/json"
"net/http"
)

const (
// GitHubのアクセストークン
accessToken = "YOUR_GITHUB_ACCESS_TOKEN"

Check failure on line 12 in src/funcs/get_activity.go

View workflow job for this annotation

GitHub Actions / lint

const `accessToken` is unused (unused)

Check failure on line 12 in src/funcs/get_activity.go

View workflow job for this annotation

GitHub Actions / lint

const `accessToken` is unused (unused)
// GitHubのGraphQL APIエンドポイント
apiEndpoint = "https://api.github.com/graphql"

Check failure on line 14 in src/funcs/get_activity.go

View workflow job for this annotation

GitHub Actions / lint

const `apiEndpoint` is unused (unused)

Check failure on line 14 in src/funcs/get_activity.go

View workflow job for this annotation

GitHub Actions / lint

const `apiEndpoint` is unused (unused)
)
// / GraphQLQuery はGraphQLのクエリを格納するための構造体です
type GraphQLQuery struct {
Query string `json:"query"`
}

// GitHubのGraphQLクエリを定義
type response struct {

Check failure on line 22 in src/funcs/get_activity.go

View workflow job for this annotation

GitHub Actions / lint

type `response` is unused (unused)

Check failure on line 22 in src/funcs/get_activity.go

View workflow job for this annotation

GitHub Actions / lint

type `response` is unused (unused)
Data struct {
User struct {
ContributionsCollection struct {
TotalCommitContributions int `graphql:"totalCommitContributions"`
TotalIssueContributions int `graphql:"totalIssueContributions"`
TotalPullRequestContributions int `graphql:"totalPullRequestContributions"`
TotalRepositoryContributions int `graphql:"totalRepositoryContributions"`
} `graphql:"contributionsCollection"`
StarredRepositories struct {
TotalCount int `graphql:"totalCount"`
} `graphql:"starredRepositories"`
} `graphql:"user(login: $username)"`
}
}


func fetchDataInTimeRange(token string, username string) (int, int, int, int, int, error) {

Check failure on line 39 in src/funcs/get_activity.go

View workflow job for this annotation

GitHub Actions / lint

func `fetchDataInTimeRange` is unused (unused)

Check failure on line 39 in src/funcs/get_activity.go

View workflow job for this annotation

GitHub Actions / lint

func `fetchDataInTimeRange` is unused (unused)
const query_frame = `
{
user(login: "%s") {
contributionsCollection {
totalCommitContributions
totalIssueContributions
totalPullRequestContributions
totalRepositoryContributions
}
starredRepositories {
totalCount
}
}
}
`

// GraphQLクエリを構築
query := fmt.Sprintf(query_frame, username)

// GraphQLクエリを実行して詳細情報を取得
request := GraphQLQuery{Query: query}
requestBody, err := json.Marshal(request)
if err != nil {
return 0, 0, 0, 0, 0, err
}

url := "https://api.github.com/graphql"
req, err := http.NewRequest("POST", url, bytes.NewBuffer(requestBody))
if err != nil {
return 0, 0, 0, 0, 0, err
}
req.Header.Set("Authorization", "Bearer "+token)

client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
return 0, 0, 0, 0, 0, err
}
defer resp.Body.Close()

var response response
if err := json.NewDecoder(resp.Body).Decode(&response); err != nil {
return 0, 0, 0, 0, 0, err
}

// 総コントリビューション数
totalCommitContributions := response.Data.User.ContributionsCollection.TotalCommitContributions
// 総スター数
totalStarredRepositories := response.Data.User.StarredRepositories.TotalCount
// 総Issue数
totalIssueContributions := response.Data.User.ContributionsCollection.TotalIssueContributions
// 総PullRequest数
totalPullRequestContributions := response.Data.User.ContributionsCollection.TotalPullRequestContributions
// 総コミット数
totalRepositoryContributions := response.Data.User.ContributionsCollection.TotalRepositoryContributions

return totalCommitContributions, totalStarredRepositories, totalIssueContributions, totalPullRequestContributions, totalRepositoryContributions, nil
}


// func main() {
// // ユーザー名
// username := "kou7306"

// // 期間を指定
// // from := time.Date(2024, 2, 1, 0, 0, 0, 0, time.UTC)
// // to := time.Date(2024, 2, 1, 23, 59, 59, 0, time.UTC)

// // GitHubのアクセストークンを設定
// token,_ :=funcs.GetTokens(0)

// // データを取得
// totalCommitContributions, totalStarredRepositories, totalIssueContributions, totalPullRequestContributions, totalRepositoryContributions, err := fetchDataInTimeRange(token, username)
// if err != nil {
// fmt.Println(err)
// return
// }

// fmt.Println("totalCommitContributions: ", totalCommitContributions)
// fmt.Println("totalStarredRepositories: ", totalStarredRepositories)
// fmt.Println("totalIssueContributions: ", totalIssueContributions)
// fmt.Println("totalPullRequestContributions: ", totalPullRequestContributions)
// fmt.Println("totalRepositoryContributions: ", totalRepositoryContributions)
// }
12 changes: 9 additions & 3 deletions src/funcs/get_commit_streak.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"log"
"net/http"
"os"

"github.com/joho/godotenv"
)

const query_frame = `
Expand All @@ -27,7 +29,7 @@ const query_frame = `
}
`

type response struct {
type res struct {
Data struct {
User struct {
ContributionsCollection struct {
Expand Down Expand Up @@ -66,6 +68,10 @@ func calculateStreak(weeks []struct {
}

func GetCommitHistory(username string) (int, []int, int, error) {
err := godotenv.Load()
if err != nil {
log.Fatalf("Error loading .env file")
}
query := fmt.Sprintf(query_frame, username)

request := GraphQLQuery{Query: query}
Expand All @@ -87,7 +93,7 @@ func GetCommitHistory(username string) (int, []int, int, error) {

// fmt.Println("response1: ", resp)

var res response
var res res
if err := json.NewDecoder(resp.Body).Decode(&res); err != nil {
log.Fatalf("Decoder failed: %v", err)
}
Expand All @@ -104,7 +110,7 @@ func GetCommitHistory(username string) (int, []int, int, error) {
}
}

// fmt.Println("response: ", res.Data.User.ContributionsCollection.ContributionCalendar.Weeks)
// fmt.Println("res: ", res.Data.User.ContributionsCollection.ContributionCalendar.Weeks)

// fmt.Println("dailyCommits: ", dailyCommits)
// fmt.Println("length of dailyCommits: ", len(dailyCommits))
Expand Down
10 changes: 5 additions & 5 deletions src/funcs/get_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"net/http"
)

// / GraphQLQuery はGraphQLのクエリを格納するための構造体です
type GraphQLQuery struct {
// / GraphQLQueries はGraphQLのクエリを格納するための構造体です
type GraphQLQueries struct {
Query string `json:"query"`
}

Expand All @@ -20,7 +20,7 @@ type Repository struct {
}

// レポジトリ取得の際のGraphQLのレスポンスを格納するための構造体です
type GraphQLResponse struct {
type GraphQLResponses struct {
Data struct {
User struct {
RepositoriesContributedTo struct {
Expand Down Expand Up @@ -76,7 +76,7 @@ func GetRepositories(username, token string) ([]Repository, error) {

// GraphQL APIにリクエストを送信
url := "https://api.github.com/graphql"
reqBody := GraphQLQuery{Query: query}
reqBody := GraphQLQueries{Query: query}
reqBodyJSON, err := json.Marshal(reqBody)
if err != nil {
fmt.Println("JSON Marshal Error:", err)
Expand All @@ -100,7 +100,7 @@ func GetRepositories(username, token string) ([]Repository, error) {
defer resp.Body.Close()

// レスポンスをパース
var response GraphQLResponse
var response GraphQLResponses
err = json.NewDecoder(resp.Body).Decode(&response)
if err != nil {
fmt.Println("JSON Decode Error:", err)
Expand Down
Loading
Loading