Skip to content

Commit cfb23d5

Browse files
committed
major overhaul
1 parent c2ddecd commit cfb23d5

11 files changed

+513
-343
lines changed

app/components/user-link.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ export default Ember.Component.extend({
1212
'href': function() {
1313
// TODO replace this with a link to a native crates.io profile
1414
// page when they exist.
15-
return 'https://github.com/' + this.get('user.login');
15+
return this.get('user.url');
1616
}.property('user'),
1717
});

app/models/user.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ export default DS.Model.extend({
66
login: DS.attr('string'),
77
api_token: DS.attr('string'),
88
avatar: DS.attr('string'),
9+
url: DS.attr('string'),
910
});

src/http.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,14 @@ use std::str;
1111
/// parse_github_response to handle the "common" processing of responses.
1212
pub fn github(app: &App, url: &str, auth: &Token)
1313
-> Result<curl::http::Response, curl::ErrCode> {
14-
info!("HTTP: {}", url);
14+
info!("GITHUB HTTP: {}", url);
15+
16+
let url = if app.config.env == ::Env::Test {
17+
format!("http://api.github.com{}", url)
18+
} else {
19+
format!("https://api.github.com{}", url)
20+
};
21+
1522
app.handle()
1623
.get(url)
1724
.header("Accept", "application/vnd.github.v3+json")

src/owner.rs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ pub struct Team {
2828
/// "github:org:team"
2929
/// An opaque unique ID, that was at one point parsed out to query Github.
3030
/// We only query membership with github using the github_id, though.
31+
/// This is the only name we should ever talk to Cargo about.
3132
pub login: String,
3233
/// Sugary goodness
3334
pub name: Option<String>,
34-
pub url: Option<String>,
3535
pub avatar: Option<String>,
3636

3737
}
@@ -118,13 +118,11 @@ impl Team {
118118
slug: String, // the name we want to find
119119
id: i32, // unique GH id (needed for membership queries)
120120
name: Option<String>, // Pretty name
121-
url: Option<String>, // URL to team info
122121
}
123122

124123
// FIXME: we just set per_page=100 and don't bother chasing pagination
125124
// links. A hundred teams should be enough for any org, right?
126-
let url = format!("http://api.github.com/orgs/{}/teams?per_page=100",
127-
org_name);
125+
let url = format!("/orgs/{}/teams", org_name);
128126
let token = http::token(req_user.gh_access_token.clone());
129127
let resp = try!(http::github(app, &url, &token));
130128
let teams: Vec<GithubTeam> = try!(http::parse_github_response(resp));
@@ -145,27 +143,26 @@ impl Team {
145143
avatar_url: Option<String>,
146144
}
147145

148-
let url = format!("http://api.github.com/orgs/{}", org_name);
146+
let url = format!("/orgs/{}", org_name);
149147
let resp = try!(http::github(app, &url, &token));
150148
let org: Org = try!(http::parse_github_response(resp));
151149

152-
Team::insert(conn, login, team.id, team.name, team.url, org.avatar_url)
150+
Team::insert(conn, login, team.id, team.name, org.avatar_url)
153151
}
154152

155153
pub fn insert(conn: &Connection,
156154
login: &str,
157155
github_id: i32,
158156
name: Option<String>,
159-
url: Option<String>,
160157
avatar: Option<String>)
161158
-> CargoResult<Self> {
162159

163160
let stmt = try!(conn.prepare("INSERT INTO teams
164-
(login, github_id, name, url, avatar)
165-
VALUES ($1, $2, $3, $4, $5)
161+
(login, github_id, name, avatar)
162+
VALUES ($1, $2, $3, $5)
166163
RETURNING *"));
167164

168-
let rows = try!(stmt.query(&[&login, &github_id, &name, &url, &avatar]));
165+
let rows = try!(stmt.query(&[&login, &github_id, &name, &avatar]));
169166
let row = rows.iter().next().unwrap();
170167
Ok(Model::from_row(&row))
171168
}
@@ -189,7 +186,7 @@ fn team_with_gh_id_contains_user(app: &App, github_id: i32, user: &User)
189186
state: String,
190187
}
191188

192-
let url = format!("http://api.github.com/teams/{}/memberships/{}",
189+
let url = format!("/teams/{}/memberships/{}",
193190
&github_id, &user.gh_login);
194191
let token = http::token(user.gh_access_token.clone());
195192
let resp = try!(http::github(app, &url, &token));
@@ -212,7 +209,6 @@ impl Model for Team {
212209
github_id: row.get("github_id"),
213210
login: row.get("login"),
214211
avatar: row.get("avatar"),
215-
url: row.get("url"),
216212
}
217213
}
218214

@@ -271,12 +267,18 @@ impl Owner {
271267
kind: String::from("user"),
272268
}
273269
}
274-
Owner::Team(Team { id, url, name, login, avatar, .. }) => {
270+
Owner::Team(Team { id, name, login, avatar, .. }) => {
271+
let url = {
272+
let mut parts = login.split(":");
273+
parts.next(); // discard github
274+
format!("https://github.com/{}/teams/{}",
275+
parts.next().unwrap(), parts.next().unwrap())
276+
};
275277
EncodableOwner {
276278
id: id,
277279
login: login,
278280
email: None,
279-
url: url,
281+
url: Some(url),
280282
avatar: avatar,
281283
name: name,
282284
kind: String::from("team"),
Lines changed: 86 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,118 @@
1-
===REQUEST 235
2-
GET http://api.github.com/orgs/contain-rs/teams HTTP/1.1
1+
===REQUEST 240
2+
GET http://api.github.com/orgs/crates-test-org/teams HTTP/1.1
33
Host: api.github.com
44
Proxy-Connection: Keep-Alive
55
Accept: application/vnd.github.v3+json
66
User-Agent: hello!
7-
Authorization: token 9d86670273ea0f7f51b9ed708d144267e0700b51
7+
Authorization: token c26185f31a0c14681a82764124bd031e9e9bccb0
88

9-
10-
===RESPONSE 1730
9+
10+
===RESPONSE 1978
1111
HTTP/1.1 200
12-
access-control-allow-credentials: true
13-
date: Wed, 12 Aug 2015 00:29:09 GMT
12+
x-ratelimit-remaining: 4960
13+
x-frame-options: deny
14+
x-ratelimit-reset: 1439854867
15+
content-length: 835
16+
x-oauth-scopes: read:org
17+
status: 200 OK
18+
x-github-request-id: 3FF5DB35:5BAB:9BBCE4C:55D26E9A
1419
content-type: application/json; charset=utf-8
1520
x-github-media-type: github.v3; format=json
21+
strict-transport-security: max-age=31536000; includeSubdomains; preload
22+
x-xss-protection: 1; mode=block
23+
access-control-expose-headers: ETag, Link, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval
24+
x-accepted-oauth-scopes: admin:org, read:org, repo, user, write:org
25+
x-ratelimit-limit: 5000
26+
content-security-policy: default-src 'none'
27+
x-served-by: 173530fed4bbeb1e264b2ed22e8b5c20
28+
cache-control: private, max-age=60, s-maxage=60
1629
access-control-allow-origin: *
17-
etag: "2a9de7a0de7cb45e3915c7ce43140a2f"
30+
etag: "a2d2e8a3bf29134386bfe28cd588d1fd"
31+
access-control-allow-credentials: true
1832
x-content-type-options: nosniff
1933
server: GitHub.com
20-
x-accepted-oauth-scopes: admin:org, read:org, repo, user, write:org
21-
x-oauth-scopes: read:org
22-
access-control-expose-headers: ETag, Link, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval
23-
cache-control: private, max-age=60, s-maxage=60
24-
x-github-request-id: 3FF5DB35:7713:2BDD963:55CA9355
25-
x-ratelimit-remaining: 4946
34+
date: Mon, 17 Aug 2015 23:30:34 GMT
2635
vary: Accept, Authorization, Cookie, X-GitHub-OTP
2736
vary: Accept-Encoding
28-
content-security-policy: default-src 'none'
29-
x-ratelimit-limit: 5000
30-
content-length: 587
31-
strict-transport-security: max-age=31536000; includeSubdomains; preload
3237
x-oauth-client-id: 89b6afdeaa6c6c7506ec
33-
x-served-by: 8a5c38021a5cd7cef7b8f49a296fee40
38+
39+
[{"name":"Owners","id":1699377,"slug":"owners","description":null,"permission":"admin","url":"https://api.github.com/teams/1699377","members_url":"https://api.github.com/teams/1699377/members{/member}","repositories_url":"https://api.github.com/teams/1699377/repos"},{"name":"just-for-crates-2","id":1699379,"slug":"just-for-crates-2","description":"","permission":"pull","url":"https://api.github.com/teams/1699379","members_url":"https://api.github.com/teams/1699379/members{/member}","repositories_url":"https://api.github.com/teams/1699379/repos"},{"name":"just-for-crates1","id":1699378,"slug":"just-for-crates1","description":"","permission":"pull","url":"https://api.github.com/teams/1699378","members_url":"https://api.github.com/teams/1699378/members{/member}","repositories_url":"https://api.github.com/teams/1699378/repos"}]
40+
===REQUEST 255
41+
GET http://api.github.com/teams/1699377/memberships/crates-tester-2 HTTP/1.1
42+
Host: api.github.com
43+
Proxy-Connection: Keep-Alive
44+
Authorization: token c26185f31a0c14681a82764124bd031e9e9bccb0
45+
Accept: application/vnd.github.v3+json
46+
User-Agent: hello!
47+
48+
49+
===RESPONSE 1227
50+
HTTP/1.1 200
51+
content-type: application/json; charset=utf-8
52+
vary: Accept, Authorization, Cookie, X-GitHub-OTP
53+
vary: Accept-Encoding
3454
x-frame-options: deny
55+
x-ratelimit-limit: 5000
56+
x-content-type-options: nosniff
57+
date: Mon, 17 Aug 2015 23:30:34 GMT
58+
cache-control: private, max-age=60, s-maxage=60
59+
x-oauth-client-id: 89b6afdeaa6c6c7506ec
60+
content-security-policy: default-src 'none'
3561
x-xss-protection: 1; mode=block
62+
x-github-media-type: github.v3; format=json
63+
access-control-allow-origin: *
64+
x-served-by: d594a23ec74671eba905bf91ef329026
65+
strict-transport-security: max-age=31536000; includeSubdomains; preload
66+
x-ratelimit-reset: 1439854867
67+
server: GitHub.com
68+
x-ratelimit-remaining: 4959
69+
x-accepted-oauth-scopes: admin:org, read:org, repo, write:org
70+
access-control-expose-headers: ETag, Link, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval
3671
status: 200 OK
37-
x-ratelimit-reset: 1439340318
72+
content-length: 91
73+
access-control-allow-credentials: true
74+
etag: "509aaf932a83319c5fc88ecce550f115"
75+
x-github-request-id: 3FF5DB35:5BA8:BD4AD45:55D26E9A
76+
x-oauth-scopes: read:org
3877

39-
[{"name":"Owners","id":1346282,"slug":"owners","description":null,"permission":"admin","url":"https://api.github.com/teams/1346282","members_url":"https://api.github.com/teams/1346282/members{/member}","repositories_url":"https://api.github.com/teams/1346282/repos"},{"name":" ~~~ Cargo! Test // \\ Team 漢字","id":1681541,"slug":"cargo-test-team","description":"Test for Cargo Teams","permission":"pull","url":"https://api.github.com/teams/1681541","members_url":"https://api.github.com/teams/1681541/members{/member}","repositories_url":"https://api.github.com/teams/1681541/repos"}]
40-
===REQUEST 246
41-
GET http://api.github.com/teams/1346282/memberships/Gankro HTTP/1.1
78+
{"state":"active","url":"https://api.github.com/teams/1699377/memberships/crates-tester-2"}
79+
===REQUEST 234
80+
GET http://api.github.com/orgs/crates-test-org HTTP/1.1
4281
Host: api.github.com
4382
Proxy-Connection: Keep-Alive
44-
Authorization: token 9d86670273ea0f7f51b9ed708d144267e0700b51
45-
User-Agent: hello!
83+
Authorization: token c26185f31a0c14681a82764124bd031e9e9bccb0
4684
Accept: application/vnd.github.v3+json
85+
User-Agent: hello!
4786

48-
49-
===RESPONSE 1218
87+
88+
===RESPONSE 2079
5089
HTTP/1.1 200
51-
x-frame-options: deny
90+
last-modified: Mon, 17 Aug 2015 23:27:29 GMT
5291
server: GitHub.com
53-
x-github-request-id: 3FF5DB35:7710:1C4F700:55CA9355
92+
strict-transport-security: max-age=31536000; includeSubdomains; preload
93+
etag: "f2fb21ecd1395923a51ab6ff4c85e0d1"
5494
access-control-expose-headers: ETag, Link, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval
55-
x-oauth-scopes: read:org
95+
access-control-allow-credentials: true
96+
content-length: 890
97+
x-accepted-oauth-scopes: admin:org, read:org, repo, user, write:org
98+
x-frame-options: deny
5699
vary: Accept, Authorization, Cookie, X-GitHub-OTP
57100
vary: Accept-Encoding
58-
x-ratelimit-reset: 1439340318
59-
x-ratelimit-limit: 5000
60-
x-accepted-oauth-scopes: admin:org, read:org, repo, write:org
61-
access-control-allow-credentials: true
62-
x-xss-protection: 1; mode=block
63-
content-type: application/json; charset=utf-8
64-
strict-transport-security: max-age=31536000; includeSubdomains; preload
101+
x-oauth-scopes: read:org
65102
cache-control: private, max-age=60, s-maxage=60
66-
content-security-policy: default-src 'none'
67-
content-length: 82
68-
status: 200 OK
69-
x-ratelimit-remaining: 4945
70-
access-control-allow-origin: *
71-
etag: "d2bb5218b23ab2a485564f2434b84bda"
103+
content-type: application/json; charset=utf-8
72104
x-github-media-type: github.v3; format=json
73105
x-content-type-options: nosniff
74-
x-served-by: 07ff1c8a09e44b62e277fae50a1b1dc4
75-
date: Wed, 12 Aug 2015 00:29:09 GMT
106+
x-served-by: a30e6f9aa7cf5731b87dfb3b9992202d
76107
x-oauth-client-id: 89b6afdeaa6c6c7506ec
108+
access-control-allow-origin: *
109+
x-ratelimit-reset: 1439854867
110+
x-ratelimit-limit: 5000
111+
content-security-policy: default-src 'none'
112+
x-ratelimit-remaining: 4958
113+
status: 200 OK
114+
x-xss-protection: 1; mode=block
115+
x-github-request-id: 3FF5DB35:5BA6:8B151EC:55D26E9B
116+
date: Mon, 17 Aug 2015 23:30:35 GMT
77117

78-
{"state":"active","url":"https://api.github.com/teams/1346282/memberships/Gankro"}
118+
{"login":"crates-test-org","id":13804222,"url":"https://api.github.com/orgs/crates-test-org","repos_url":"https://api.github.com/orgs/crates-test-org/repos","events_url":"https://api.github.com/orgs/crates-test-org/events","members_url":"https://api.github.com/orgs/crates-test-org/members{/member}","public_members_url":"https://api.github.com/orgs/crates-test-org/public_members{/member}","avatar_url":"https://avatars.githubusercontent.com/u/13804222?v=3","description":null,"public_repos":0,"public_gists":0,"followers":0,"following":0,"html_url":"https://github.com/crates-test-org","created_at":"2015-08-15T00:07:30Z","updated_at":"2015-08-17T23:27:29Z","type":"Organization","total_private_repos":0,"owned_private_repos":0,"private_gists":0,"disk_usage":0,"collaborators":0,"billing_email":"[email protected]","plan":{"name":"free","space":976562499,"private_repos":0}}

0 commit comments

Comments
 (0)