Skip to content

Commit

Permalink
tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
rolfbjarne committed Mar 28, 2019
1 parent 4cb2019 commit 7a97f3b
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 66 deletions.
1 change: 0 additions & 1 deletion tests/sampletester/Configuration.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using System.IO;
using System.Reflection;

Expand Down
62 changes: 4 additions & 58 deletions tests/sampletester/GitHub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,73 +2,19 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Runtime.Serialization.Json;
using System.Xml;

using NUnit.Framework;

using Xamarin.Tests;

public static class GitHub {
static WebClient CreateClient ()
{
var client = new WebClient ();
client.Headers.Add (HttpRequestHeader.UserAgent, "xamarin");
var xharness_github_token_file = Environment.GetEnvironmentVariable ("XHARNESS_GITHUB_TOKEN_FILE");
if (!string.IsNullOrEmpty (xharness_github_token_file) && File.Exists (xharness_github_token_file))
client.Headers.Add (HttpRequestHeader.Authorization, File.ReadAllText (xharness_github_token_file));
return client;
}

static string[] GetFiles (string user, string repo)
{
var fn = Path.Combine (Configuration.SampleRootDirectory, $"{repo}.filelist");
if (File.Exists (fn))
return File.ReadAllLines (fn);
Directory.CreateDirectory (Path.GetDirectoryName (fn));

using (var client = CreateClient ()) {
byte [] data;
try {
data = client.DownloadData ($"https://api.github.com/repos/{user}/{repo}/git/trees/master?recursive=1");
} catch (WebException we) {
string rsp = we.Message;
try {
foreach (var header in we.Response.Headers.AllKeys)
rsp += $"\n{header}={we.Response.Headers [header]}";
using (var webreader = new StreamReader (we.Response.GetResponseStream ()))
rsp += "\n" + webreader.ReadToEnd ();
} catch {
}

return new string [] { $"Failed to load {user}/{repo}: {rsp}" };
}
var reader = JsonReaderWriterFactory.CreateJsonReader (data, new XmlDictionaryReaderQuotas ());
var doc = new XmlDocument ();
doc.Load (reader);
var rv = new List<string> ();
foreach (XmlNode node in doc.SelectNodes ("/root/tree/item/path")) {
rv.Add (node.InnerText);
}

File.WriteAllLines (fn, rv.ToArray ());
return rv.ToArray ();
}

}

public static string [] GetProjects (string user, string repo, bool clone)
public static string [] GetProjects (string user, string repo)
{
IEnumerable<string> files;

if (clone) {
var dir = CloneRepository (user, repo);
files = Directory.GetFiles (dir, "*.*", SearchOption.AllDirectories);
files = files.Select ((v) => v.Substring (dir.Length).TrimStart ('/'));
} else {
files = GetFiles (user, repo);
}
var dir = CloneRepository (user, repo);
files = Directory.GetFiles (dir, "*.*", SearchOption.AllDirectories);
files = files.Select ((v) => v.Substring (dir.Length).TrimStart ('/'));

return files
.Where ((v) => {
Expand Down
1 change: 1 addition & 0 deletions tests/sampletester/MacSampleTester.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;

using NUnit.Framework;

namespace Samples {
Expand Down
1 change: 1 addition & 0 deletions tests/sampletester/PrebuiltAppTester.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;

using NUnit.Framework;

namespace Samples {
Expand Down
8 changes: 1 addition & 7 deletions tests/sampletester/SampleTester.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.IO;
using System.Net;
using System.Runtime.Serialization.Json;
using System.Text;
using System.Threading;
using System.Xml;

using NUnit.Framework;

Expand Down Expand Up @@ -153,7 +147,7 @@ public void BuildSample ([ValueSource ("GetSampleData")] SampleTestData sampleTe
protected static ProjectInfo [] GetExecutableProjects (string repo)
{
if (!projects.TryGetValue (repo, out var rv)) {
var project_paths = GitHub.GetProjects ("xamarin", repo, true);
var project_paths = GitHub.GetProjects ("xamarin", repo);

// We can filter out project we don't care about.
rv = project_paths.
Expand Down
1 change: 1 addition & 0 deletions tests/sampletester/XamarinFormsSampleTester.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;

using NUnit.Framework;

namespace Samples {
Expand Down

0 comments on commit 7a97f3b

Please sign in to comment.