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

changelog github integration #466

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
101 changes: 95 additions & 6 deletions changed.d
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,15 @@ module changed;

import std.net.curl, std.conv, std.exception, std.algorithm, std.csv, std.typecons,
std.stdio, std.datetime, std.array, std.string, std.file, std.format, std.getopt,
std.path, std.functional;
std.path, std.functional, std.json;

import std.range.primitives, std.traits;

struct BugzillaEntry
{
int id;
string summary;
Nullable!int githubId;
}

struct ChangelogEntry
Expand Down Expand Up @@ -126,7 +127,7 @@ string escapeParens(string input)
}

/** Get a list of all bugzilla issues mentioned in revRange */
auto getIssues(string revRange)
int[] getIssues(string revRange)
{
import std.process : execute, pipeProcess, Redirect, wait;
import std.regex : ctRegex, match, splitter;
Expand Down Expand Up @@ -155,6 +156,7 @@ auto getIssues(string revRange)

foreach (line; p.stdout.byLine())
{
writeln(line);
if (auto m = match(line.stripLeft, closedRE))
{
m.captures[1]
Expand All @@ -165,16 +167,22 @@ auto getIssues(string revRange)
}
}
}
return issues.data.sort().release.uniq;
return issues.data.sort().release.uniq.array;
}

BugzillaEntry[][string][string] getClosedGithubIssues(string revRange)
{
BugzillaEntry[][string][string] entries;
return entries;
}

/** Generate and return the change log as a string. */
auto getBugzillaChanges(string revRange)
BugzillaEntry[][string][string] getBugzillaChanges(string revRange)
{
// component (e.g. DMD) -> bug type (e.g. regression) -> list of bug entries
BugzillaEntry[][string][string] entries;

auto issues = getIssues(revRange);
int[] issues = getIssues(revRange);
// abort prematurely if no issues are found in all git logs
if (issues.empty)
return entries;
Expand Down Expand Up @@ -224,6 +232,77 @@ auto getBugzillaChanges(string revRange)
return entries;
}

struct GithubIssue {
int number;
string title;
string body_;
DateTime closedAt;
}

GithubIssue[] getGithubIssues(string repo, DateTime startDate,
DateTime endDate)
{
const query = `
query($repo: String!, $startDate: DateTime!) {
repository(owner: "burner", name: $repo) {
name
id
issues(states: CLOSED, first: 100
, filterBy: { since: $startDate })
{
edges {
node {
number
title
id
body
closedAt
}
}
pageInfo {
endCursor
startCursor
hasNextPage
hasPreviousPage
}
}
}
}`;
JSONValue toSend;
toSend["query"] = query;
toSend["variables"] = `{ "repo": "%s", "startDate": "%sZ", "endDate": "%sZ" }`
.format("graphqld", startDate.toISOExtString(), endDate.toISOExtString());
string requestData = toSend.toPrettyString();

writefln("RD %s", requestData);
string ghToken = readText("gh_token").strip();
string bearer = format("Bearer %s", ghToken);
writefln("'%s' '%s'", ghToken, bearer);

HTTP http = HTTP("https://api.github.com/graphql");
http.addRequestHeader("Authorization", bearer);
http.setPostData(requestData, "application/json");

char[] response;
try {
http.onReceive = (ubyte[] d) {
response = cast(char[])d;
return d.length;
};
http.perform();
} catch(Exception e) {
throw e;
}

writefln("RS %s", cast(string)response);

string s = cast(string)response;
JSONValue j = parseJSON(s);
writeln(j.toPrettyString());

return [];
}

/**
Reads a single changelog file.

Expand Down Expand Up @@ -391,6 +470,12 @@ void writeBugzillaChanges(Entries, Writer)(Entries entries, Writer w)
}
}

int main(string[] args) {
getGithubIssues("phobos", DateTime(2023,1,1), DateTime(2023,12,1));
return 0;
}

__EOF__
thewilsonator marked this conversation as resolved.
Show resolved Hide resolved
int main(string[] args)
{
auto outputFile = "./changelog.dd";
Expand Down Expand Up @@ -434,6 +519,8 @@ Please supply a bugzilla version
writeln("Skipped querying Bugzilla for changes. Please define a revision range e.g ./changed v2.072.2..upstream/stable");
}

getGithubIssues("phobos", DateTime(2023,1,1), DateTime(2023,12,1));

// location of the changelog files
alias Repo = Tuple!(string, "name", string, "headline", string, "path", string, "prefix");
auto repos = [Repo("dmd", "Compiler changes", "changelog", "dmd."),
Expand Down Expand Up @@ -473,7 +560,9 @@ Please supply a bugzilla version
// Accumulate Bugzilla issues
typeof(revRange.getBugzillaChanges) bugzillaChanges;
if (revRange.length)
bugzillaChanges = revRange.getBugzillaChanges;
{
bugzillaChanges = revRange.getBugzillaChanges();
}

// Accumulate contributors from the git log
version(Contributors_Lib)
Expand Down